Translate

Sonntag, 20. März 2016

Android Java-Wo ist die APK?

Android-Java-AsyncTask Beispiel

package com.sshapp.tim.sshservershutdownandrestart;

import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.ScrollView;
import android.widget.TextView;

import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;

import java.text.DateFormat;
import java.util.Date;
import java.util.Properties;

public class Main extends AppCompatActivity{

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setTitle("MyApp");
        Button mybutton1 = (Button) 
           findViewById(R.id.mybutton1);
        Button mybutton2 = (Button)
           findViewById(R.id.mybutton2);

        //Set click events        mybutton1.setOnClickListener(new View.OnClickListener(){
            @Override            public void onClick(View view) {
                onRestartClick((Button) view);
            }
        });
        mybutton12.setOnClickListener(new View.OnClickListener(){
            @Override            public void onClick(View view) {
                onShutdownClick((Button) view);
            }
        });
    }

    private void onRestartClick(Button view) {
        new AsyncSSHTask().execute("param1");
    }

    private void onShutdownClick(Button view) {
        new AsyncSSHTask().execute("param1");
    }

    private void ScrollViewDown(){
        ScrollView scrollViewLogging = (ScrollView)
           findViewById(R.id.scrollViewScroll);
        scrollViewLogging.post(new Runnable() {
            public void run() {
                ScrollView scrollViewLogging = (ScrollView)
                   findViewById(R.id.scrollViewScroll);
                scrollViewLogging.fullScroll(View.FOCUS_DOWN);
            }
        });
    }

    private void Log(String text){
        TextView textViewLogging = (TextView)
           findViewById(R.id.textViewLogging);
        String currentDateTimeString = DateFormat. 
           getDateTimeInstance().format(new Date());
        textViewLogging.append(currentDateTimeString + ": "  
           + text + "\n");
        ScrollViewDown();
    }

    public void LogPublic(String text) {
        final String str = text;
        Main.this.runOnUiThread(new Runnable() {
            @Override            public void run() {
                Log(str);
            }
        });
    }

    public class MyAsyncTask extends AsyncTask<String, Integer, 
       Long> {
        @Override        protected Long doInBackground(String... params) {
            try            {
                //Your code here
                return new Long(1);
            }
            catch (Exception ex)
            {
                LogPublic(ex.getMessage());
                return new Long(0);
            }
        }
    }

}

Android-Java-ScrollView nach ganz unten scrollen


ScrollView mScrollView= (ScrollView) findViewById(R.id.mScrollView);
mScrollView.post(new Runnable() { public void run() { mScrollView.fullScroll(View.FOCUS_DOWN); } });

Android-Java-Scrollbar (Zoomen)

ScrollView nutzen, um zu zoomen

Android-Java-Aktuelle Zeit ausgeben

Android-Java-SSH-Fehler Error message 'java.net.SocketException: socket failed: EACCES (Permission denied)'

Android-Java-Toolbar ohne Settings

@Overridepublic boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.    //getMenuInflater().inflate(R.menu.menu_main, menu);    return true;
}
 
entfernen --> Settings (3 Punkte sind weg) 

Android-Java-Toolbar-Überschrift ändern

Android-Java-App-Icon ändern