1. M Haidar Hanif
  2. kargu

Commits

M Haidar Hanif  committed 8a9fa51

Prepare for new activity to get input

  • Participants
  • Parent commits caccaee
  • Branches develop

Comments (0)

Files changed (5)

File res/layout/activity_display_number.xml

View file
  • Ignore whitespace
+<?xml version="1.0" encoding="utf-8"?>
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+              android:orientation="vertical"
+              android:layout_width="match_parent"
+              android:layout_height="match_parent">
+
+</LinearLayout>

File res/layout/activity_main.xml

View file
  • Ignore whitespace
 <LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
-    android:orientation="vertical"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:background="@color/light_gray"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
-    android:background="@color/light_gray"
-    android:padding="8dip"
+    android:orientation="vertical"
+    android:paddingBottom="@dimen/activity_vertical_margin"
+    android:paddingLeft="@dimen/activity_horizontal_margin"
+    android:paddingRight="@dimen/activity_horizontal_margin"
+    android:paddingTop="@dimen/activity_vertical_margin"
+    tools:context=".MainActivity"
     >
 
+    <!-- Title Area -->
+
     <TextView
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:paddingBottom="16dip"
         />
 
-    <RelativeLayout
+    <!-- Input Area -->
+
+    <LinearLayout
         xmlns:android="http://schemas.android.com/apk/res/android"
-        xmlns:tools="http://schemas.android.com/tools"
         android:layout_width="match_parent"
-        android:layout_height="match_parent"
-        android:paddingBottom="@dimen/activity_vertical_margin"
-        android:paddingLeft="@dimen/activity_horizontal_margin"
-        android:paddingRight="@dimen/activity_horizontal_margin"
-        android:paddingTop="@dimen/activity_vertical_margin"
-        tools:context=".MainActivity" >
+        android:layout_height="wrap_content"
+        android:orientation="horizontal"
+        android:padding="8dip"
+        >
+
+        <EditText
+            android:id="@+id/edit_inputNumber"
+            android:hint="@string/edit_inputNumber"
+            android:layout_weight="1"
+            android:layout_width="0dp"
+            android:layout_height="wrap_content"
+            />
 
         <Button
-            android:id="@+id/button_help"
+            android:id="@+id/button_getNumber"
+            android:text="@string/button_getInput"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:text="@string/button_help"
-            android:layout_centerHorizontal="true"
-            android:layout_alignParentTop="true"
-            android:onClick="openDialog"
+            android:onClick="getNumber"
             />
 
+    </LinearLayout>
+
+    <!-- Additionals -->
+
+    <RelativeLayout
+        xmlns:android="http://schemas.android.com/apk/res/android"
+        android:orientation="vertical"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        >
+
         <Button
-            android:id="@+id/button_about"
+            android:id="@+id/button_reset"
+            android:text="@string/button_reset"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:text="@string/button_about"
             android:layout_centerHorizontal="true"
-            android:layout_below="@+id/button_help"
-            android:onClick="openDialog"
+            android:layout_alignParentTop="true"
             />
 
     </RelativeLayout>

File res/values/strings.xml

View file
  • Ignore whitespace
 <?xml version="1.0" encoding="utf-8"?>
+
 <resources>
 
     <string name="app_name">Kargu</string>
     <string name="about_title">Tentang Aplikasi</string>
     <string name="button_about">Tentang</string>
     <string name="action_about">Tentang</string>
-    <string name="about_dialog">Kargu Listrik, memperkirakan biaya penggunaan listrik tanpa ragu dan membudayakan hemat energi</string>
+    <string name="about_dialog">Kargu Listrik, memperkirakan biaya penggunaan listrik tanpa ragu serta membudayakan hemat energi</string>
 
     <string name="button_close">Tutup</string>
 
+    <string name="edit_inputNumber">0</string>
+    <string name="button_getInput">Ambil</string>
+    <string name="button_reset">Kosongkan</string>
+
 </resources>

File src/com/mhaidarhanif/android/kargu/DisplayNumberActivity.java

View file
  • Ignore whitespace
+package com.mhaidarhanif.android.kargu;
+
+import android.annotation.SuppressLint;
+import android.os.Build;
+import android.os.Bundle;
+import android.view.MenuItem;
+
+public class DisplayNumberActivity extends MainActivity {
+
+  @SuppressLint("NewApi")
+
+  @Override
+  protected void onCreate(Bundle savedInstanceState) {
+    super.onCreate(savedInstanceState);
+    setContentView(R.layout.activity_display_number);
+
+    /** Check min. API level version to use ActionBar API */
+    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.CUR_DEVELOPMENT) {
+      // Show Up button in ActionBar
+      getActionBar().setDisplayHomeAsUpEnabled(true);
+    }
+  }
+
+  /** Inherit method from ActionBar */
+  @Override
+  public boolean onOptionsItemsSelected(MenuItem item) {
+    switch (item.getItemId()) {
+      case android.R.id.home:
+        NavUtils.navigateUpFromSameTask(this);
+        return true;
+    }
+    return super.onOptionsItemSelected(item);
+  }
+
+}

File src/com/mhaidarhanif/android/kargu/MainActivity.java

View file
  • Ignore whitespace
 import android.os.Bundle;
 import android.view.Menu;
 import android.view.View;
+import android.widget.EditText;
 
 public class MainActivity extends Activity {
 
   // For complete title purpose, will be used later
   // String appEditionName = getString(R.string.app_name) + " " + getString(R.string.edition_name);
 
+  public final static String EXTRA_NUMBER = "com.mhaidarhanif.android.kargu.NUMBER";
+
   @Override
   protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     return true;
   }
 
+  /** Called when press getNumber */
+  public void getNumber(View view) {
+    Intent intent = new Intent(this, DisplayNumberActivity.class);
+    EditText editText = (EditText) findViewById(R.id.edit_inputNumber);
+    String number = editText.getText().toString();
+    intent.putExtra(EXTRA_NUMBER, number);
+    startActivity(intent);
+  }
+
   public void openDialog(View v) {
     Intent intent = new Intent(MainActivity.this, AboutDialogActivity.class);
     startActivity(intent);