Android Open Source - TATupload Browser Accessor






From Project

Back to project page TATupload.

License

The source code is released under:

GNU General Public License

If you think the Android project TATupload listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package uk.org.sucu.tatupload;
//  w  w w.  ja  va  2  s.  c  o m
import java.util.List;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Spinner;

public class BrowserAccessor {

  public static List<ResolveInfo> getResolvers(Context context){
    //build an intent that launches to the webscript url
    Uri uri = Uri.parse(context.getString(R.string.scriptURL));
    Intent browserIntent = new Intent(Intent.ACTION_VIEW);
    browserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    browserIntent.setData(uri);
    //return a list of the packages that can handle the intent
    return context.getPackageManager().queryIntentActivities(browserIntent, PackageManager.MATCH_DEFAULT_ONLY);
  }

  public static String getPackageName(ResolveInfo resolveInfo){
    return resolveInfo.activityInfo.packageName;    
  }
  
  public static String getName(ResolveInfo resolveInfo){
    return resolveInfo.activityInfo.name;
  }
  
  public static boolean browserSet(Context context){
    Settings settings = new Settings(context);
    String browserPackageName = settings.getChosenBrowserPackage();
    String browserName = settings.getChosenBrowserName();
    //null is returned as default if no saved browser package name is able to be loaded
    return ((browserPackageName != null) && (browserName != null));
  }
  
  public static boolean isInstalled(String packageName, String className, Context context){
    //get a list of all installed packages
    List<ResolveInfo> apps = getResolvers(context);
    //return true if one has the desired class and packageName
    for(ResolveInfo app : apps){
      if(getPackageName(app).equals(packageName) && getName(app).equals(className)){
        return true;
      }
    }
    //else return false
    return false;
  }
  
  public static void openBrowserChoicePopup(Context context, boolean cancelable){
    openBrowserChoicePopup(context, cancelable, null);
  }
  
  @SuppressLint("InflateParams")
  public static void openBrowserChoicePopup(final Context context, boolean cancelable, final Runnable onCloseCode){
    final View viewToLoad = LayoutInflater.from(context).inflate(R.layout.browser_choice_popup, null);  
    
    AlertDialog.Builder builder = new AlertDialog.Builder(context)
    .setTitle("Select browser")
    .setView(viewToLoad)
    .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
      @Override
      public void onClick(DialogInterface dialog, int which) {
        //get the selected ResolveInfo
        Spinner spin = (Spinner) viewToLoad.findViewById(R.id.browserSpinner);
        ResolveInfo selected = (ResolveInfo) spin.getSelectedItem();
        //get the packagename
        String packageName = getPackageName(selected);
        String className = getName(selected);
        //save it
        new Settings(context).setBrowserData(packageName, className);
        if(onCloseCode != null){
          onCloseCode.run();
        }
      }
    })
    .setCancelable(cancelable);
    //add a cancel button if applicable
    if(cancelable){
      builder.setNegativeButton(android.R.string.cancel, null);
    }
    
    builder.create();
    
    List<ResolveInfo> resolvers = getResolvers(context);
    
    //connect the dialogs spinner to the data structure
    Spinner spin = (Spinner) viewToLoad.findViewById(R.id.browserSpinner);
    ResolveInfoArrayAdapter adapter = new ResolveInfoArrayAdapter(context, android.R.layout.simple_spinner_item, resolvers);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spin.setAdapter(adapter);

    builder.show();
  }
  
  public static boolean usable(Context context){
    //load the browser data
    Settings settings = new Settings(context);
    String packageName = settings.getChosenBrowserPackage();
    String className = settings.getChosenBrowserName();
    //check they're actual saved values, not the defaults from failure
    if(packageName == Settings.BROWSER_PACKAGE_DEFAULT || className == Settings.BROWSER_NAME_DEFAULT){
      return false;
    }
    //check it's still installed
    return isInstalled(packageName, className, context);
  }
  
}




Java Source Code List

org.apache.pig.impl.util.ObjectSerializer.java
uk.org.sucu.tatupload.BrowserAccessor.java
uk.org.sucu.tatupload.MessageArrayAdapter.java
uk.org.sucu.tatupload.NetCaller.java
uk.org.sucu.tatupload.Notifications.java
uk.org.sucu.tatupload.ParameterArrayAdapter.java
uk.org.sucu.tatupload.ResolveInfoArrayAdapter.java
uk.org.sucu.tatupload.Settings.java
uk.org.sucu.tatupload.TabContent.java
uk.org.sucu.tatupload.TabManager.java
uk.org.sucu.tatupload.TatUploadApplication.java
uk.org.sucu.tatupload.activity.MainActivity.java
uk.org.sucu.tatupload.activity.OptionActivity.java
uk.org.sucu.tatupload.activity.ParameterViewActivity.java
uk.org.sucu.tatupload.activity.SmsReviewActivity.java
uk.org.sucu.tatupload.activity.TutorialActivity.java
uk.org.sucu.tatupload.message.SmsList.java
uk.org.sucu.tatupload.message.SmsReceiver.java
uk.org.sucu.tatupload.message.Text.java
uk.org.sucu.tatupload.parse.Parameters.java
uk.org.sucu.tatupload.parse.Parser.java
uk.org.sucu.tatupload.parse.Property.java