- Forum-Beiträge: 101
15.12.2013, 20:35:50 via Website
15.12.2013 20:35:50 via Website
Alles, was fett und unterstrichen ist, wird von eclipse unterstrichelt.
Hier der Code der MainActivity.java:
2
3import org.apache.http.util.EncodingUtils;
4
5import android.R;
6import android.R.layout;
7import android.annotation.SuppressLint;
8import android.app.Activity;
9import android.app.AlertDialog;
10import android.content.DialogInterface;
11import android.content.Intent;
12import android.os.Bundle;
13import android.view.Menu;
14import android.view.MenuInflater;
15import android.view.View;
16import android.view.View.OnClickListener;
17import android.webkit.CookieManager;
18import android.webkit.WebSettings.PluginState;
19import android.webkit.WebView;
20import android.webkit.WebViewClient;
21import android.widget.Button;
22import android.widget.EditText;
23
24
25public class MainActivity extends Activity {
26
27 private EditText etusername;
28 private EditText etpassword;
29 private Button btlogin;
30 private Button btfeedback;
31
32 @Override
33 public void onCreate(Bundle savedInstanceState) {
34 super.onCreate(savedInstanceState);
35 setContentView(R.layout.activity_main);
36
37 Button btlogin = (Button) findViewById(R.id.btlogin)
38
39 EditText etusername = (EditText) findViewById(R.id.etusername);
40
41 findViewById(R.id.btfeedback).setOnClickListener(new OnClickListener() {
42 @Override
43 public void onClick(View v) {
44 Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
45 String[] recipients = new String[]{"tbremer19@gmail.com", "",};
46 emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients);
47 emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Feedback zur Vertretungsplan App");
48 emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Fehler, Lob, Kritik oder Funktionswünsche:");
49 emailIntent.setType("text/plain");
50 startActivity(Intent.createChooser(emailIntent, "Sende Mail mit..."));
51 finish();
52 }
53 });
54
55
56
57 new AlertDialog.Builder(MainActivity.this)
58
59 .setTitle("BETA")
60
61 .setMessage("Die App befindet sich zurzeit noch in einer Beta-Testphase. Wenn du Fehler in meiner App findest, klick einfach auf den Feedback-Button.")
62
63 .setNeutralButton("Fenster Schließen",
64
65 new DialogInterface.OnClickListener() {
66
67 public void onClick(DialogInterface dialog,
68
69 int which) {
70
71 }
72
73 }).show();
74
75
76
77 //button
78
79 findViewById(R.id.btlogin).setOnClickListener( new View.OnClickListener() {
80
81
82 @SuppressLint("SetJavaScriptEnabled") @Override
83 public void onClick(View v) {
84
85 EditText etusername = (EditText) findViewById (R.id.etusername);
86 etusername.setText(etusername.getText().toString());
87 EditText etpassword = (EditText) findViewById (R.id.etpassword);
88 etpassword.setText(etpassword.getText().toString());
89
90 WebView wv = new WebView(MainActivity.this);
91 setContentView(wv);
92 wv.getSettings().setBuiltInZoomControls(true);
93 CookieManager.getInstance().setAcceptCookie(true);
94 wv.getSettings().setJavaScriptEnabled(true);
95 wv.getSettings().setLoadWithOverviewMode(true);
96 wv.getSettings().setUseWideViewPort(true);
97 wv.loadUrl("javascript: {" +
98 "document.getElementById('username').value = '"+etusername+"';" +
99 "document.getElementById('password').value = '"+etpassword+"';" +
100 "var frms = document.getElementsByName('login');" +
101 "frms[0].submit(); };");
102 wv.setWebViewClient(new WebViewClient() {
103 @Override
104 public boolean shouldOverrideUrlLoading(WebView view, String url) {
105 return false;
106 }
107 });
108
109
110 String url = "http://www.ggnauen.de/index.php";
111 String data = "username" + etusername + "&password" + etpassword;
112
113 wv.postUrl(url, EncodingUtils.getBytes(data, "base64"));
114
115
116
117 }
118
119
120 });
121
122
123
124 }
125
126
127
128
129
130
131
132
133
134
135
136
137 }
Und hier die activity_main.xml:
2 xmlns:tools="http://schemas.android.com/tools"
3 android:layout_width="match_parent"
4 android:layout_height="match_parent"
5 android:paddingBottom="@dimen/activity_vertical_margin"
6 android:paddingLeft="@dimen/activity_horizontal_margin"
7 android:paddingRight="@dimen/activity_horizontal_margin"
8 android:paddingTop="@dimen/activity_vertical_margin"
9 tools:context=".MainActivity"
10 >
11
12 <Button
13 android:id="@+id/btlogin"
14 android:layout_width="wrap_content"
15 android:layout_height="wrap_content"
16 android:layout_alignParentLeft="true"
17 android:layout_alignParentRight="true"
18 android:layout_below="@+id/etpassword"
19 android:layout_marginTop="19dp"
20 android:text="Anmelden" />
21
22 <TextView
23 android:id="@+id/textView1"
24 android:layout_width="wrap_content"
25 android:layout_height="wrap_content"
26 android:layout_alignLeft="@+id/etusername"
27 android:layout_alignParentTop="true"
28 android:text="Login"
29 android:textAppearance="?android:attr/textAppearanceLarge" />
30
31 <EditText
32 android:id="@+id/etusername"
33 android:layout_width="wrap_content"
34 android:layout_height="wrap_content"
35 android:layout_alignLeft="@+id/etpassword"
36 android:layout_alignParentRight="true"
37 android:layout_below="@+id/textView1"
38 android:layout_marginTop="16dp"
39 android:ems="10"
40 android:hint="Benutzername" >
41
42 <requestFocus />
43 </EditText>
44
45 <EditText
46 android:id="@+id/etpassword"
47 android:layout_width="wrap_content"
48 android:layout_height="wrap_content"
49 android:layout_alignLeft="@+id/btlogin"
50 android:layout_alignParentRight="true"
51 android:layout_below="@+id/etusername"
52 android:ems="10"
53 android:hint="Passwort" />
54
55 <Button
56 android:id="@+id/btfeedback"
57 android:layout_width="wrap_content"
58 android:layout_height="wrap_content"
59 android:layout_alignParentBottom="true"
60 android:layout_alignParentLeft="true"
61 android:layout_alignRight="@+id/btlogin"
62 android:text="Feedback" />
63
64
65
66</RelativeLayout>
Danke, tbremer19
— geändert am 15.12.2013, 20:37:31
LG Optimus Me mit Root
Empfohlener redaktioneller Inhalt
Mit Deiner Zustimmung wird hier ein externer Inhalt geladen.
Mit Klick auf den oben stehenden Button erklärst Du Dich damit einverstanden, dass Dir externe Inhalte angezeigt werden dürfen. Dabei können personenbezogene Daten an Drittanbieter übermittelt werden. Mehr Infos dazu findest Du in unserer Datenschutzerklärung.