Java Code Examples for android.app.Application

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project android-client, under directory /xwiki-android-test-core/src/org/xwiki/android/rest/ral/test/.

Source file: TestDocumentRaoCreate.java

  33 
vote

@Override public void setUp() throws Exception {
  super.setUp();
  username=TestConstants.USERNAME;
  password=TestConstants.PASSWORD;
  serverUrl=TestConstants.SERVER_URL;
  wikiName=TestConstants.WIKI_NAME;
  spaceName=TestConstants.SPACE_NAME;
  pageName=TestConstants.CREATE_PAGE_NAME + "-" + count;
  attachmentName=TestConstants.ATTACHMENT_NAME;
  objClsName1=TestConstants.OBJECT_CLASS_NAME_1;
  objClsName2=TestConstants.OBJECT_CLASS_NAME_2;
  rm=new XmlRESTFulManager(serverUrl,username,password);
  api=rm.getRestConnector();
  rao=rm.newDocumentRao();
  doc=new Document(wikiName,spaceName,pageName);
  doc.setTitle(pageName);
  api.deletePage(wikiName,spaceName,pageName);
  if (count == 9) {
    Application sys=XWikiApplicationContext.getInstance();
    FileOutputStream fos=sys.openFileOutput(attachmentName,Context.MODE_WORLD_READABLE);
    PrintWriter writer=new PrintWriter(fos);
    writer.println("this is a text attachment.");
    writer.flush();
    writer.close();
    FileInputStream fis=sys.openFileInput(attachmentName);
    byte[] buff=new byte[30];
    int i=0;
    while (i != -1) {
      i=fis.read(buff);
    }
    Log.d(TAG,new String(buff));
    af1=sys.getFileStreamPath(attachmentName);
  }
  Log.d(TAG,"setup test method:" + count);
}
 

Example 2

From project daily-money, under directory /dailymoney/src/com/bottleworks/dailymoney/context/.

Source file: Contexts.java

  32 
vote

/** 
 * for ui context only
 * @return
 */
public String getApplicationVersionName(){
  if (uiActivity != null) {
    Application app=(uiActivity).getApplication();
    String name=app.getPackageName();
    PackageInfo pi;
    try {
      pi=app.getPackageManager().getPackageInfo(name,0);
      return pi.versionName;
    }
 catch (    NameNotFoundException e) {
    }
  }
  return "";
}
 

Example 3

From project droid-fu, under directory /src/main/java/com/github/droidfu/activities/.

Source file: BetterDefaultActivity.java

  32 
vote

@Override protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  this.wasCreated=true;
  this.currentIntent=getIntent();
  Application application=getApplication();
  if (application instanceof DroidFuApplication) {
    ((DroidFuApplication)application).setActiveContext(getClass().getCanonicalName(),this);
  }
}
 

Example 4

From project motelib, under directory /src/com/cafbit/motelib/.

Source file: MoteContext.java

  32 
vote

/** 
 * Return the MoteContext singleton for this application. This singleton object is fully implemented by each application to allow per-app customizations. We ask for an activity so we can fetch the Application object via getApplication().  The application object must implement the MoteApplication interface. We don't use a Context parameter, since it's not clear to me that the Context.getApplicationContext() method will always return the Application object in the future.  (Even though it seems to, today.)
 * @param activity
 * @return The MoteContext singleton for the application.
 */
public static MoteContext getInstance(Activity activity){
  Application application=activity.getApplication();
  if (!(application instanceof MoteApplication)) {
    throw new RuntimeException("Application singleton must implement MoteApplication.");
  }
  MoteApplication moteApplication=(MoteApplication)application;
  return moteApplication.getMoteContext();
}
 

Example 5

From project LoL-Chat, under directory /src/com/rei/lolchat/ui/.

Source file: Login.java

  31 
vote

@Override protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  Application app=getApplication();
  if (app instanceof BeemApplication) {
    mBeemApplication=(BeemApplication)app;
    if (mBeemApplication.isConnected()) {
      startActivity(new Intent(this,ContactList.class));
      finish();
    }
 else     if (!mBeemApplication.isAccountConfigured()) {
      startActivity(new Intent(this,Account.class));
      finish();
    }
  }
  setContentView(R.layout.login);
  mTextView=(TextView)findViewById(R.id.log_as_msg);
}
 

Example 6

From project platform_packages_apps_launcher, under directory /src/com/android/launcher/.

Source file: Launcher.java

  31 
vote

/** 
 * Registers various intent receivers. The current implementation registers only a wallpaper intent receiver to let other applications change the wallpaper.
 */
private void registerIntentReceivers(){
  if (sWallpaperReceiver == null) {
    final Application application=getApplication();
    sWallpaperReceiver=new WallpaperIntentReceiver(application,this);
    IntentFilter filter=new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED);
    application.registerReceiver(sWallpaperReceiver,filter);
  }
 else {
    sWallpaperReceiver.setLauncher(this);
  }
  IntentFilter filter=new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
  filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
  filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
  filter.addDataScheme("package");
  registerReceiver(mApplicationsReceiver,filter);
}
 

Example 7

From project RebeLauncher, under directory /src/com/dirtypepper/rebelauncher/.

Source file: Launcher.java

  31 
vote

/** 
 * Registers various intent receivers. The current implementation registers only a wallpaper intent receiver to let other applications change the wallpaper.
 */
private void registerIntentReceivers(){
  boolean useNotifReceiver=AlmostNexusSettingsHelper.getNotifReceiver(this);
  if (useNotifReceiver && mCounterReceiver == null) {
    mCounterReceiver=new CounterReceiver(this);
    mCounterReceiver.setCounterListener(new CounterReceiver.OnCounterChangedListener(){
      public void onTrigger(      String pname,      int counter,      int color){
        updateCountersForPackage(pname,counter,color);
      }
    }
);
    registerReceiver(mCounterReceiver,mCounterReceiver.getFilter());
  }
  if (sWallpaperReceiver == null) {
    final Application application=getApplication();
    sWallpaperReceiver=new WallpaperIntentReceiver(application,this);
    IntentFilter filter=new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED);
    application.registerReceiver(sWallpaperReceiver,filter);
  }
 else {
    sWallpaperReceiver.setLauncher(this);
  }
  IntentFilter filter=new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
  filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
  filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
  filter.addDataScheme("package");
  registerReceiver(mApplicationsReceiver,filter);
  filter=new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
  registerReceiver(mCloseSystemDialogsReceiver,filter);
  filter=new IntentFilter();
  filter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE);
  filter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
  registerReceiver(mApplicationsReceiver,filter);
}
 

Example 8

From project SqueezeControl, under directory /src/com/squeezecontrol/.

Source file: SqueezeService.java

  31 
vote

public SqueezeService(Application application){
  mContext=application;
  initialize();
  IntentFilter filter=new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE");
  mContext.registerReceiver(mConnectivityStateReceiver,filter);
}
 

Example 9

From project wheelmap-android, under directory /wheelmap/wheelmap/src/main/java/org/wheelmap/android/app/.

Source file: AppProperties.java

  31 
vote

/** 
 * @param context
 * @throws IOException
 */
@Inject public AppProperties(Provider<Application> applicationProvider){
  final BufferedInputStream stream;
{
    final Application app=applicationProvider.get();
    try {
      stream=new BufferedInputStream(app.getAssets().open(Constants.APP_PROPERTIES_ASSETS_FILE_NAME));
      try {
        properties=new Properties();
        properties.load(stream);
      }
  finally {
        UtilsMisc.closeSilently(stream);
      }
    }
 catch (    IOException e) {
      e.printStackTrace();
      Log.e(LOG_TAG,"excpetio by instatiating of app properties" + e.toString());
    }
  }
}
 

Example 10

From project twidere, under directory /src/org/mariotaku/twidere/util/.

Source file: ImageUploaderInterface.java

  30 
vote

public static ImageUploaderInterface getInstance(final Application application,final String uploader_name){
  if (uploader_name == null)   return null;
  final Intent intent=new Intent(INTENT_ACTION_EXTENSION_UPLOAD_IMAGE);
  final ComponentName component=ComponentName.unflattenFromString(uploader_name);
  intent.setComponent(component);
  if (application.getPackageManager().queryIntentServices(intent,0).size() != 1)   return null;
  return new ImageUploaderInterface(application,uploader_name);
}
 

Example 11

From project agit, under directory /agit/src/main/java/com/madgag/agit/operations/.

Source file: GitAsyncTask.java

  29 
vote

@Inject public GitAsyncTask(Application application,@Named("uiThread") Handler handler,@Assisted GitOperation operation,@Assisted OperationLifecycleSupport lifecycleSupport){
  super(application);
  handler(handler);
  this.operation=operation;
  this.lifecycleSupport=lifecycleSupport;
}
 

Example 12

From project android-sdk, under directory /src/main/java/com/mobeelizer/mobile/android/.

Source file: MobeelizerApplication.java

  29 
vote

public static MobeelizerApplication createApplication(final Application mobeelizer){
  MobeelizerApplication application=new MobeelizerApplication();
  Bundle metaData=application.getMetaData(mobeelizer);
  String device=metaData.getString(META_DEVICE);
  String entityPackage=metaData.getString(META_PACKAGE);
  String definitionXml=metaData.getString(META_DEFINITION_ASSET);
  String developmentRole=metaData.getString(META_DEVELOPMENT_ROLE);
  int databaseVersion=metaData.getInt(META_DATABASE_VERSION,1);
  String url=metaData.getString(META_URL);
  String stringMode=metaData.getString(META_MODE);
  if (entityPackage == null) {
    throw new IllegalStateException(META_PACKAGE + " must be set in manifest file.");
  }
  if (definitionXml == null) {
    definitionXml="application.xml";
  }
  application.initApplication(mobeelizer,device,entityPackage,developmentRole,definitionXml,databaseVersion,url,stringMode);
  return application;
}
 

Example 13

From project android_aosp_packages_apps_Settings, under directory /src/com/android/settings/applications/.

Source file: ApplicationsState.java

  29 
vote

static ApplicationsState getInstance(Application app){
synchronized (sLock) {
    if (sInstance == null) {
      sInstance=new ApplicationsState(app);
    }
    return sInstance;
  }
}
 

Example 14

From project be.norio.twunch.android, under directory /src/be/norio/twunch/android/util/.

Source file: PrefsUtils.java

  29 
vote

public static void initialize(Application application){
  CONTEXT=application;
  int version=getPrefs().getInt(KEY_PREFS_VERSION,VER_LEGACY);
switch (version) {
case VER_LEGACY:
    if (LOGV)     Log.v(TAG,"Upgrading settings from version " + version + " to version "+ VER_LAUNCH);
  version=VER_LAUNCH;
}
PrefsUtils.apply(getPrefs().edit().putInt(KEY_PREFS_VERSION,version));
}
 

Example 15

From project creamed_glacier_app_settings, under directory /src/com/android/settings/applications/.

Source file: ApplicationsState.java

  29 
vote

static ApplicationsState getInstance(Application app){
synchronized (sLock) {
    if (sInstance == null) {
      sInstance=new ApplicationsState(app);
    }
    return sInstance;
  }
}
 

Example 16

From project ElectricSleep, under directory /src/com/androsz/electricsleepbeta/util/.

Source file: GoogleAnalyticsSessionHelper.java

  29 
vote

public static GoogleAnalyticsSessionHelper getInstance(String key,Application appContext){
  if (INSTANCE == null) {
    INSTANCE=new GoogleAnalyticsSessionHelper(key,appContext);
  }
  return INSTANCE;
}
 

Example 17

From project FBReaderJ, under directory /src/org/geometerplus/android/fbreader/.

Source file: SelectionCopyAction.java

  29 
vote

@Override protected void run(Object... params){
  final String text=Reader.getTextView().getSelectedText();
  Reader.getTextView().clearSelection();
  final ClipboardManager clipboard=(ClipboardManager)BaseActivity.getApplication().getSystemService(Application.CLIPBOARD_SERVICE);
  clipboard.setText(text);
  UIUtil.showMessageText(BaseActivity,ZLResource.resource("selection").getResource("textInBuffer").getValue().replace("%s",clipboard.getText()));
}
 

Example 18

From project k-9, under directory /src/com/fsck/k9/controller/.

Source file: MessagingController.java

  29 
vote

/** 
 * @param application  {@link K9}
 */
private MessagingController(Application application){
  mApplication=application;
  mThread=new Thread(this);
  mThread.setName("MessagingController");
  mThread.start();
  if (memorizingListener != null) {
    addListener(memorizingListener);
  }
}
 

Example 19

From project npr-android-app, under directory /src/org/npr/android/util/.

Source file: Tracker.java

  29 
vote

public static Tracker instance(Application application){
  if (tracker == null) {
    tracker=new Tracker(application);
  }
  tracker.begin();
  return tracker;
}
 

Example 20

From project OAK, under directory /oak-library/src/main/java/oak/http/.

Source file: OakHttpTool.java

  29 
vote

@Inject public OakHttpTool(Application application){
  mApplication=application;
  installCache();
  try {
    appVersionName=mApplication.getPackageManager().getPackageInfo(mApplication.getPackageName(),0).versionName;
    appVersionCode=mApplication.getPackageManager().getPackageInfo(mApplication.getPackageName(),0).versionCode;
  }
 catch (  PackageManager.NameNotFoundException e) {
    Log.e(TAG,"There was an error setting the version for the app");
  }
}
 

Example 21

From project Ohmage_Phone, under directory /src/org/ohmage/.

Source file: OhmageApplication.java

  29 
vote

public void setupObject(boolean restore){
  PackageManager pm=getPackageManager();
  ApplicationInfo ai=getApplicationInfo();
  String name=(String)pm.getApplicationLabel(ai);
  if (restore) {
    try {
      GlobalConfig config=GlobalConfig.getInstance();
      byte[] byte_in=null;
      SystemState.Application state;
      CCNHandle handle=config.getCCNHandle();
      byte_in=config.loadConfig("applications",name);
      state=SystemState.Application.parseFrom(byte_in);
      this._pull_rate=state.getPullRate();
      setupObject();
      for (      String stream_name : state.getDataStreamsList()) {
        DataStream stream=new DataStream(handle,this,stream_name,true);
        addDataStream(stream);
      }
    }
 catch (    InvalidProtocolBufferException e) {
      e.printStackTrace();
    }
catch (    IOException e) {
      e.printStackTrace();
    }
  }
 else {
    setupObject();
  }
}
 

Example 22

From project platform_packages_apps_settings, under directory /src/com/android/settings/applications/.

Source file: ApplicationsState.java

  29 
vote

static ApplicationsState getInstance(Application app){
synchronized (sLock) {
    if (sInstance == null) {
      sInstance=new ApplicationsState(app);
    }
    return sInstance;
  }
}
 

Example 23

From project QuotaForAndroid, under directory /Quota/src/com/southfreo/quota/control/.

Source file: QuotaService.java

  29 
vote

public void startMyService(Application app){
  Log.d(TAG,"started");
  pm=ProviderManager.getInstance();
  sm=SlotManager.getInstance();
  String ns=Context.NOTIFICATION_SERVICE;
  mNotificationManager=(NotificationManager)getSystemService(ns);
  startUpdateTimer();
}
 

Example 24

From project roboguice, under directory /roboguice/src/main/java/roboguice/event/.

Source file: EventManager.java

  29 
vote

/** 
 * Registers given method with provided context and event.
 */
public void registerObserver(Context context,Object instance,Method method,Class event){
  if (!isEnabled())   return;
  if (context instanceof Application)   throw new RuntimeException("You may not register event handlers on the Application context");
  Map<Class<?>,Set<ObserverReference<?>>> methods=registrations.get(context);
  if (methods == null) {
    methods=new HashMap<Class<?>,Set<ObserverReference<?>>>();
    registrations.put(context,methods);
  }
  Set<ObserverReference<?>> observers=methods.get(event);
  if (observers == null) {
    observers=new HashSet<ObserverReference<?>>();
    methods.put(event,observers);
  }
  observers.add(new ObserverReference(instance,method));
}