/*
* Copyright 2013 two forty four a.m. LLC <http://www.twofortyfouram.com>
*
* 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.integreight.onesheeld.plugin;
import android.annotation.TargetApi;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import com.integreight.onesheeld.R;
import com.twofortyfouram.locale.BreadCrumber;
public abstract class AbstractPluginActivity extends FragmentActivity {
private boolean mIsCancelled = false;
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
setupTitleApi11();
} else {
setTitle(BreadCrumber.generateBreadcrumb(getApplicationContext(),
getIntent(), getString(R.string.app_name)));
}
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setupTitleApi11() {
CharSequence callingApplicationLabel = null;
try {
callingApplicationLabel = getPackageManager().getApplicationLabel(
getPackageManager().getApplicationInfo(getCallingPackage(),
0));
} catch (final NameNotFoundException e) {
if (Constants.IS_LOGGABLE) {
Log.e(Constants.LOG_TAG, "Calling package couldn't be found", e); //$NON-NLS-1$
}
}
if (null != callingApplicationLabel) {
setTitle(callingApplicationLabel);
}
}
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(
R.menu.twofortyfouram_locale_help_save_dontsave, menu);
return true;
}
@Override
public boolean onMenuItemSelected(final int featureId, final MenuItem item) {
final int id = item.getItemId();
if (android.R.id.home == id) {
finish();
return true;
} else if (R.id.twofortyfouram_locale_menu_dontsave == id) {
mIsCancelled = true;
finish();
return true;
} else if (R.id.twofortyfouram_locale_menu_save == id) {
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
protected boolean isCanceled() {
return mIsCancelled;
}
}