Commits

M Haidar Hanif committed e707f4b Merge

Merge branch 'feature/getInput' into develop

Basic input with editText and button.
Basic output with textView in new Activity.

  • Participants
  • Parent commits caccaee, 346c142

Comments (0)

Files changed (8)

File AndroidManifest.xml

         android:debuggable="true"
         android:allowBackup="true"
         android:icon="@drawable/ic_launcher"
-        android:label="@string/app_name"
-        android:theme="@style/AppTheme">
+        android:label="@string/name_app"
+        android:theme="@style/AppTheme" >
 
         <activity
             android:name=".MainActivity"
-            android:label="@string/app_name"
-            android:launchMode="singleTask">
+            android:label="@string/name_app"
+            android:launchMode="singleTask" >
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.LAUNCHER" />
         </activity>
 
         <activity
+            android:name=".DisplayNumberActivity"
+            android:label="@string/title_number"
+            android:parentActivityName="com.mhaidarhanif.android.kargu.MainActivity" >
+            <meta-data
+                android:name="android.support.PARENT_ACTIVITY"
+                android:value="com.mhaidarhanif.android.kargu.MainActivity" />
+        </activity>
+
+        <activity
             android:name=".AboutDialogActivity"
-            android:label="@string/about_title"
-            android:theme="@android:style/Theme.Dialog">
+            android:label="@string/title_about"
+            android:theme="@android:style/Theme.Dialog" >
         </activity>
 
     </application>
     <url>https://github.com/mhaidarh/kargu/</url>
 
     <properties>
-        <platform.version> 2.3.3
+        <platform.version> 4.1.1.4
         </platform.version>
     </properties>
 
             <version>${platform.version}</version>
             <scope>provided</scope>
         </dependency>
+        <dependency>
+            <groupId>com.google.android</groupId>
+            <artifactId>support-v4</artifactId>
+            <version>r7</version>
+        </dependency>
     </dependencies>
 
     <build>

File res/layout/activity_about.xml

 
     <TextView
         android:id="@+id/about_title"
-        android:text="@string/about_title"
+        android:text="@string/title_about"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:gravity="center_horizontal"
         />
 
     <TextView
-        android:text="@string/about_dialog"
+        android:text="@string/dialog_about"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:gravity="center_horizontal"

File res/layout/activity_display_number.xml

+<?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

 <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:text="@string/appedition_name"
+        android:text="@string/name_appedition"
         android:gravity="center_horizontal"
         android:textStyle="bold"
         android:textSize="@dimen/font_large"
         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

 <?xml version="1.0" encoding="utf-8"?>
+
 <resources>
 
-    <string name="app_name">Kargu</string>
-    <string name="edition_name">Listrik</string>
-    <string name="appedition_name">Kargu Listrik</string>
-    <string name="app_version">Versi 0.1</string>
-    <string name="app_tagline">Memperkirakan biaya penggunaan tanpa ragu</string>
+    <string name="name_app">Kargu</string>
+    <string name="name_edition">Listrik</string>
+    <string name="name_appedition">Kargu Listrik</string>
+    <string name="version_app">Versi 0.1</string>
+    <string name="tagline_app">Memperkirakan biaya penggunaan tanpa ragu</string>
+
+    <string name="title_number">Angka yang diambil</string>
 
-    <string name="settings_title">Pengaturan Lengkap</string>
+    <string name="title_settings">Pengaturan Lengkap</string>
     <string name="action_settings">Pengaturan</string>
 
-    <string name="help_title">Bantuan Penggunaan</string>
+    <string name="title_help">Bantuan Penggunaan</string>
     <string name="button_help">Bantuan</string>
     <string name="action_help">Bantuan</string>
-    <string name="help_dialog">Masukkan data mengenai daya listrik dan alat elektronik yang akan Anda gunakan</string>
+    <string name="dialog_help">Masukkan data mengenai daya listrik dan alat elektronik yang akan Anda gunakan</string>
 
-    <string name="about_title">Tentang Aplikasi</string>
+    <string name="title_about">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="dialog_about">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

+package com.mhaidarhanif.android.kargu;
+
+import android.annotation.SuppressLint;
+import android.annotation.TargetApi;
+import android.content.Intent;
+import android.os.Build;
+import android.os.Bundle;
+import android.support.v4.app.NavUtils;
+import android.view.MenuItem;
+import android.widget.TextView;
+
+public class DisplayNumberActivity extends MainActivity {
+
+  @SuppressLint("NewApi")
+
+  /** Display new activity */
+  @TargetApi(11)
+  protected void onCreate(Bundle savedInstanceState) {
+    super.onCreate(savedInstanceState);
+    setContentView(R.layout.activity_display_number);
+
+    // Get number from intent
+    Intent intent = getIntent();
+    String number = intent.getStringExtra(MainActivity.EXTRA_NUMBER);
+
+    // Create text view
+    TextView textView = new TextView(this);
+    textView.setTextSize(40);
+    textView.setText(number);
+
+    // Set text view as activity layout
+    setContentView(textView);
+
+    /** Check minimum API level number to use ActionBar API */
+    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
+      // Show Up button in ActionBar
+      getActionBar().setDisplayHomeAsUpEnabled(true);
+    }
+  }
+
+  /** Inherit method from ActionBar */
+  @Override
+  public boolean onOptionsItemSelected(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

 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);
+  // String appEditionName = getString(R.string.app_name) + " " + getString(R.string.name_edition);
+
+  public final static String EXTRA_NUMBER = "com.mhaidarhanif.android.kargu.NUMBER";
 
   @Override
   protected void onCreate(Bundle 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);