Search in sources :

Example 1 with Application

use of org.flyve.mdm.agent.room.entity.Application in project android-mdm-agent by flyve-mdm.

the class FragmentAppList method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_app_list, container, false);
    dataBase = AppDataBase.getAppDatabase(this.getActivity());
    pb = v.findViewById(R.id.progressBar);
    txtNoData = v.findViewById(R.id.txtNoData);
    final SwipeRefreshLayout swipeLayout = v.findViewById(R.id.swipe_container);
    swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            swipeLayout.setRefreshing(false);
            loadData();
        }
    });
    lst = v.findViewById(R.id.lst);
    lst.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            Application app = apps[i];
            Intent intent = new Intent(FragmentAppList.this.getContext(), InstallAppActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.putExtra("APP_ID", app.appId);
            intent.putExtra("APP_PATH", app.appPath);
            FragmentAppList.this.getContext().startActivity(intent);
        }
    });
    loadData();
    return v;
}
Also used : AdapterView(android.widget.AdapterView) Intent(android.content.Intent) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) Application(org.flyve.mdm.agent.room.entity.Application)

Example 2 with Application

use of org.flyve.mdm.agent.room.entity.Application in project android-mdm-agent by flyve-mdm.

the class InstallAppActivity method onActivityResult.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // pending
    String status = "1";
    switch(requestCode) {
        case APP_INSTALL_REQUEST:
            if (resultCode == RESULT_OK) {
                FlyveLog.d("Package Installation Success");
                // installed
                status = "2";
            } else {
                FlyveLog.d("Installation failed");
            }
    }
    try {
        PackageManager packageManager = InstallAppActivity.this.getPackageManager();
        PackageInfo packageInfo = packageManager.getPackageArchiveInfo(appPath, 0);
        packageInfo.applicationInfo.sourceDir = appPath;
        packageInfo.applicationInfo.publicSourceDir = appPath;
        String appName = packageManager.getApplicationLabel(packageInfo.applicationInfo).toString();
        String appPackage = packageInfo.packageName;
        AppDataBase dataBase = AppDataBase.getAppDatabase(InstallAppActivity.this);
        if (dataBase.applicationDao().getApplicationById(id).length <= 0) {
            Application apps = new Application();
            apps.appId = id;
            apps.appName = appName;
            apps.appPath = appPath;
            // 1 pending | 2 installed
            apps.appStatus = status;
            apps.appPackage = appPackage;
            dataBase.applicationDao().insert(apps);
        } else {
            // update status to installed
            dataBase.applicationDao().updateStatus(id, "2");
        }
        if (status.equals("2")) {
            // remove notifications if exists
            NotificationManager notificationManager = (NotificationManager) InstallAppActivity.this.getSystemService(Context.NOTIFICATION_SERVICE);
            notificationManager.cancel(Integer.parseInt(id));
        } else {
            Helpers.sendToNotificationBar(InstallAppActivity.this, Integer.parseInt(id), getString(R.string.app_pending_to_install), appName, true, MainActivity.class);
        }
    } catch (Exception ex) {
        FlyveLog.e(ex.getMessage());
    }
    finish();
}
Also used : PackageManager(android.content.pm.PackageManager) AppDataBase(org.flyve.mdm.agent.room.database.AppDataBase) NotificationManager(android.app.NotificationManager) PackageInfo(android.content.pm.PackageInfo) Application(org.flyve.mdm.agent.room.entity.Application) ActivityNotFoundException(android.content.ActivityNotFoundException)

Example 3 with Application

use of org.flyve.mdm.agent.room.entity.Application in project android-mdm-agent by flyve-mdm.

the class ApplicationsAdapter method getView.

/**
 * Get a View that displays the data at the specified position
 * @param position of the item within the adapter's data set of the item whose View we want
 * @param convertView the old View to reuse, if possible
 * @param parent the parent that this View will eventually be attached to
 * @return View a View corresponding to the data at the specified position
 */
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    Application app = data[position];
    View vi = inflater.inflate(R.layout.list_item_application, null);
    TextView txtStatus = vi.findViewById(R.id.txtStatus);
    String status = parent.getResources().getString(R.string.app_installed);
    if (app.appStatus.equals("1")) {
        status = parent.getResources().getString(R.string.app_pending);
    }
    txtStatus.setText(status);
    TextView txtAppName = vi.findViewById(R.id.txtAppName);
    txtAppName.setText(app.appName);
    TextView txtPackageName = vi.findViewById(R.id.txtPackageName);
    txtPackageName.setText(app.appPackage);
    ImageView imgApp = vi.findViewById(R.id.imgApp);
    imgApp.setImageDrawable(Helpers.getApplicationImage(parent.getContext(), app.appPackage));
    return vi;
}
Also used : TextView(android.widget.TextView) ImageView(android.widget.ImageView) Application(org.flyve.mdm.agent.room.entity.Application) TextView(android.widget.TextView) ImageView(android.widget.ImageView) View(android.view.View)

Aggregations

Application (org.flyve.mdm.agent.room.entity.Application)3 View (android.view.View)2 TextView (android.widget.TextView)2 NotificationManager (android.app.NotificationManager)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1 Intent (android.content.Intent)1 PackageInfo (android.content.pm.PackageInfo)1 PackageManager (android.content.pm.PackageManager)1 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)1 AdapterView (android.widget.AdapterView)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1 AppDataBase (org.flyve.mdm.agent.room.database.AppDataBase)1