Beruflich Dokumente
Kultur Dokumente
java
package id.sch.smktelkom_mlg.mywallet.beranda_screen;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.graphics.drawable.RoundedBitmapDrawable;
import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import id.sch.smktelkom_mlg.mywallet.Controller.SaldoController;
import id.sch.smktelkom_mlg.mywallet.Fragment.FragmentCategory;
import id.sch.smktelkom_mlg.mywallet.Fragment.FragmentDailyReport;
import id.sch.smktelkom_mlg.mywallet.Fragment.FragmentHome;
import id.sch.smktelkom_mlg.mywallet.Fragment.FragmentMonthlyReport;
import id.sch.smktelkom_mlg.mywallet.R;
import id.sch.smktelkom_mlg.mywallet.Utils.SPManager;
import id.sch.smktelkom_mlg.mywallet.Utils.Utils;
import id.sch.smktelkom_mlg.mywallet.saldo_screen.SetSaldo_activity;
Toolbar toolbar;
DrawerLayout drawer;
NavigationView navigationView;
FragmentManager fragmentManager;
FragmentTransaction fragmentTransaction;
Fragment fragment = null;
SPManager prefManager;
FloatingActionButton fabBtn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar1);
setSupportActionBar(toolbar);
fragmentManager = getFragmentManager();
if (savedInstanceState == null) {
fragment = new FragmentHome();
callFragment(fragment);
}
ident = b.getString("IDENT");
View header =
((NavigationView)findViewById(R.id.nav_view1)).getHeaderView(0);
((TextView)
header.findViewById(R.id.tv_nombre_usuario_menu1)).setText(itemUsuario.getNombre())
;
((TextView)
header.findViewById(R.id.tv_correo_menu1)).setText(itemUsuario.getCorreo());
Bitmap bitmapsinfoto =
BitmapFactory.decodeResource(getResources(),R.drawable.imagen);
RoundedBitmapDrawable roundedBitmapDrawablesinfoto =
RoundedBitmapDrawableFactory.create(getResources(), bitmapsinfoto);
roundedBitmapDrawablesinfoto.setCircular(true);
((ImageView)
header.findViewById(R.id.imageView1)).setImageDrawable(roundedBitmapDrawablesinfoto
);
if(itemUsuario.getBytes()!=null){
byte[] foodImage = itemUsuario.getBytes();
Bitmap bitmap = BitmapFactory.decodeByteArray(foodImage, 0,
foodImage.length);
((ImageView)
header.findViewById(R.id.imageView1)).setImageBitmap(bitmap);
((ImageView)
header.findViewById(R.id.imageView1)).setImageDrawable(roundedBitmapDrawable);
}
/**
* Set FAB Show or Hide
*/
public void showFloatingActionButton() {
fabBtn.show();
};
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout1);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.home_activity, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings1) {
showSaldoDialog();
return true;
}
if (id == R.id.action_reset1) {
prefManager.setFirstTimeLaunch(true);
getApplicationContext().deleteDatabase("uangku");
Intent intent =new
Intent(getApplicationContext(),SetSaldo_activity.class);
startActivity(intent);
finish();
return true;
}
if (id == R.id.share_action1) {
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
String shareBodyText = getResources().getString(R.string.sharebody);
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
getResources().getString(R.string.sharesubject) );
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT,
shareBodyText);
startActivity(Intent.createChooser(sharingIntent,
getResources().getString(R.string.sharedialog)));
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* Change Saldo Dialog
*/
saldoKontrol.updateSaldo(Integer.parseInt(newsaldo.getText().toString()));
callFragment(new FragmentHome());
}
})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogBox, int id)
{
dialogBox.cancel();
}
});
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_home1) {
// Handle the camera action
fragment = new FragmentHome();
callFragment(fragment);
} else if (id == R.id.nav_kategori1) {
fragment = new FragmentCategory();
callFragment(fragment);
} else if (id == R.id.nav_harian1) {
fragment = new FragmentDailyReport();
callFragment(fragment);
} else if (id == R.id.nav_bulanan1) {
fragment = new FragmentMonthlyReport();
callFragment(fragment);
} else if (id == R.id.nav_bacres1) {
backupRestoredialog();
} else if (id == R.id.nav_info1) {
showAboutDialog();
}
/**
* Show About Dialog
*/
private void showAboutDialog() {
View mView = getLayoutInflater().inflate(R.layout.dialog_about, null,
false);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setIcon(R.mipmap.ic_launcher);
builder.setTitle(R.string.app_name);
builder.setView(mView);
builder.create();
builder.show();
}
/**
* Selec Dialog For Backup or Restore
*/
private void backupRestoredialog() {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Backup & Restore");
builder.setItems(R.array.dialog_backup, new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case 0:
Toast.makeText(Home_activity.this, Utils.doBackup(),
Toast.LENGTH_SHORT).show();
break;
case 1:
callFragment(new FragmentHome());
Toast.makeText(Home_activity.this, Utils.doRestore(),
Toast.LENGTH_SHORT).show();
break;
}
}
});
builder.show();
}
/**
* Start Selected Fragment
*/
tools:context="id.sch.smktelkom_mlg.mywallet.beranda_screen.Home_activity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar1"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab1"
android:layout_width="wrap_content"
android:layouta_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:tint="@android:color/white"
app:srcCompat="@android:drawable/ic_input_add" />
</android.support.design.widget.CoordinatorLayout>
Content_home_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content_main_home1"
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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".beranda_screen.Home_activity"
tools:showIn="@layout/app_bar_home_activity">
<FrameLayout
android:id="@+id/frame_container1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
Activity_home.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="@layout/app_bar_home_activity"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_home_activity"
app:menu="@menu/activity_home_drawer" />
</android.support.v4.widget.DrawerLayout>
Fragment_home.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff">
<LinearLayout
android:id="@+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/linearLayout"
android:layout_alignParentTop="true"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.5"
android:background="@color/colorPrimaryDark">
<TextView
android:id="@+id/info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/currentSaldo"
android:layout_centerHorizontal="true"
android:text="@string/availablemoney"
android:textColor="#fff" />
<TextView
android:id="@+id/currentSaldo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textColor="#fff"
android:textSize="50sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:background="@color/global_color_green_primary_light"
android:padding="10dp">
<Button
android:id="@+id/prev"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/colorAccent"
android:text="Prev"
android:textAlignment="center"
android:textSize="20sp" />
<Button
android:id="@+id/next"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="@color/colorAccent"
android:text="NEXT"
android:textAlignment="center"
android:textSize="20sp" />
<Button
android:id="@+id/tgl"
style="@style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toEndOf="@+id/prev"
android:layout_toStartOf="@+id/next"
android:text="2017-03-21"
android:textAlignment="center"
android:textSize="20sp" />
<ListView
android:id="@+id/outList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/tgl"
android:divider="@null"
android:dividerHeight="0dp"
android:scrollbars="none"></ListView>
<LinearLayout
android:id="@+id/emptyview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:orientation="vertical"
android:visibility="gone">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:srcCompat="@drawable/ic_add_alert_black_24dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/noexpense"
android:textSize="16dp"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/colorPrimary"
android:orientation="horizontal"
android:padding="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="@string/todayexpense"
android:textColor="#fff" />
<TextView
android:id="@+id/todayOut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="123.000"
android:textColor="#fff" />
</LinearLayout>
</RelativeLayout>
Nav_header_home_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="@dimen/nav_header_height"
android:background="@drawable/side_nav_bar"
android:gravity="bottom"
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"
android:theme="@style/ThemeOverlay.AppCompat.Dark">
<ImageView
android:id="@+id/imageView1"
android:layout_width="80dp"
android:layout_height="80dp"
android:paddingTop="@dimen/nav_header_vertical_spacing"
app:srcCompat="@drawable/imagen" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:text="Android Studio"
android:id="@+id/tv_nombre_usuario_menu1"
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
<TextView
android:id="@+id/tv_correo_menu1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="android.studio@android.com" />
</LinearLayout>
Menu -> activity_home_drawer.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="@+id/nav_home1"
android:icon="@drawable/ic_home_black_24dp"
android:title="Home" />
<item
android:id="@+id/nav_kategori1"
android:icon="@drawable/ic_playlist_add_black_24dp"
android:title="Kategori" />
</group>
<item android:title="Laporan">
<menu>
<group android:checkableBehavior="single">
<item
android:id="@+id/nav_harian1"
android:icon="@drawable/ic_assessment_black_24dp"
android:title="Harian" />
<item
android:id="@+id/nav_bulanan1"
android:icon="@drawable/ic_assessment_black_24dp"
android:title="Bulanan" />
</group>
</menu>
</item>
<item android:title="Tools">
<menu>
<item
android:id="@+id/nav_bacres1"
android:icon="@drawable/ic_archive_black_24dp"
android:title="Backup & Restore" />
<item
android:id="@+id/nav_info1"
android:icon="@drawable/ic_info_black_24dp"
android:title="Tentang" />
</menu>
</item>
</menu>
Menu -> home_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/share_action1"
android:actionProviderClass="android.widget.ShareActionProvider"
android:icon="@drawable/ic_share"
android:title="Share"
app:showAsAction="always" />
<item
android:id="@+id/action_settings1"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never" />
<item
android:id="@+id/action_reset1"
android:orderInCategory="100"
android:title="@string/action_reset"
app:showAsAction="never" />
</menu>