Permalink
Browse files

Add new feature "invoke Activity from side navigation"

  • Loading branch information...
johnkil committed Oct 6, 2012
1 parent f244e9b commit 06671dfe5256637ae4b78e625874354a9a70024e
Showing with 62 additions and 17 deletions.
  1. +2 −2 sample/AndroidManifest.xml
  2. +60 −15 sample/src/com/devspark/sidenavigation/sample/MainActivity.java
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.devspark.sidenavigation.sample"
- android:versionCode="3"
- android:versionName="1.02" >
+ android:versionCode="4"
+ android:versionName="1.1" >
<uses-sdk
android:minSdkVersion="7"
@@ -1,12 +1,29 @@
+/*
+ * Copyright (C) 2012 Evgeny Shishkin
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package com.devspark.sidenavigation.sample;
+import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.MenuItem;
+import com.devspark.sidenavigation.sample.R;
import com.devspark.sidenavigation.ISideNavigationCallback;
-import com.devspark.sidenavigation.R;
import com.devspark.sidenavigation.SideNavigationView;
/**
@@ -17,6 +34,9 @@
public class MainActivity extends SherlockActivity implements
ISideNavigationCallback {
+ public static final String EXTRA_TITLE = "com.devspark.sidenavigation.sample.extra.MTGOBJECT";
+ public static final String EXTRA_RESOURCE_ID = "com.devspark.sidenavigation.sample.extra.RESOURCE_ID";
+
private ImageView icon;
private SideNavigationView sideNavigationView;
@@ -29,7 +49,14 @@ protected void onCreate(Bundle savedInstanceState) {
sideNavigationView = (SideNavigationView) findViewById(R.id.side_navigation_view);
sideNavigationView.setMenuItems(R.menu.side_navigation_menu);
sideNavigationView.setMenuClickCallback(this);
-
+
+ if (getIntent().hasExtra(EXTRA_TITLE)) {
+ String title = getIntent().getStringExtra(EXTRA_TITLE);
+ int resId = getIntent().getIntExtra(EXTRA_RESOURCE_ID, 0);
+ setTitle(title);
+ icon.setImageResource(resId);
+ }
+
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
@@ -49,36 +76,31 @@ public boolean onOptionsItemSelected(MenuItem item) {
public void onSideNavigationItemClick(int itemId) {
switch (itemId) {
case R.id.side_navigation_menu_item1:
- setTitle(R.string.title1);
- icon.setImageResource(R.drawable.ic_android1);
+ invokeActivity(getString(R.string.title1), R.drawable.ic_android1);
break;
case R.id.side_navigation_menu_item2:
- setTitle(R.string.title2);
- icon.setImageResource(R.drawable.ic_android2);
+ invokeActivity(getString(R.string.title2), R.drawable.ic_android2);
break;
case R.id.side_navigation_menu_item3:
- setTitle(R.string.title3);
- icon.setImageResource(R.drawable.ic_android3);
+ invokeActivity(getString(R.string.title3), R.drawable.ic_android3);
break;
case R.id.side_navigation_menu_item4:
- setTitle(R.string.title4);
- icon.setImageResource(R.drawable.ic_android4);
+ invokeActivity(getString(R.string.title4), R.drawable.ic_android4);
break;
case R.id.side_navigation_menu_item5:
- setTitle(R.string.title5);
- icon.setImageResource(R.drawable.ic_android5);
+ invokeActivity(getString(R.string.title5), R.drawable.ic_android5);
break;
default:
- break;
+ return;
}
-
+ finish();
}
-
+
@Override
public void onBackPressed() {
// hide menu if it shown
@@ -89,4 +111,27 @@ public void onBackPressed() {
}
}
+ /**
+ * Start activity from SideNavigation.
+ *
+ * @param title
+ * title of Activity
+ * @param resId
+ * resource if of background image
+ */
+ private void invokeActivity(String title, int resId) {
+ Intent intent = new Intent(this, MainActivity.class);
+ intent.putExtra(EXTRA_TITLE, title);
+ intent.putExtra(EXTRA_RESOURCE_ID, resId);
+
+ // all of the other activities on top of it will be closed and this
+ // Intent will be delivered to the (now on top) old activity as a
+ // new Intent.
+ intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+
+ startActivity(intent);
+ // no animation of transition
+ overridePendingTransition(0, 0);
+ }
+
}

0 comments on commit 06671df

Please sign in to comment.