Search in sources :

Example 1 with AppData

use of org.flyve.mdm.agent.data.localstorage.AppData in project android-mdm-agent by flyve-mdm.

the class FragmentInformation method onCreateView.

/**
 * Instantiate the user interface View
 * @param inflater the object that can be used to inflate any views in the fragment
 * @param container the parent View the fragment's UI should be attached to
 * @param savedInstanceState this fragment is being re-constructed from a previous saved state
 * @return View the View for the fragment's UI
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View v = inflater.inflate(R.layout.fragment_information, container, false);
    cache = new AppData(FragmentInformation.this.getActivity());
    ImageView imgLogo = v.findViewById(R.id.imgLogo);
    imgLogo.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!cache.getEasterEgg()) {
                countEasterEgg++;
                if (countEasterEgg > 6 && countEasterEgg <= 10) {
                    Toast.makeText(FragmentInformation.this.getActivity(), getResources().getQuantityString(R.plurals.easter_egg_attempts, countEasterEgg, countEasterEgg), Toast.LENGTH_SHORT).show();
                }
                if (countEasterEgg >= 10) {
                    Toast.makeText(FragmentInformation.this.getActivity(), getResources().getString(R.string.easter_egg_success), Toast.LENGTH_SHORT).show();
                    cache.setEasterEgg(true);
                    ((MainActivity) FragmentInformation.this.getActivity()).loadListDrawer(0, "");
                }
            }
        }
    });
    txtNameUser = v.findViewById(R.id.txtNameUser);
    txtEmailUser = v.findViewById(R.id.txtDescriptionUser);
    imgUser = v.findViewById(R.id.imgLogoUser);
    txtNameSupervisor = v.findViewById(R.id.txtNameSupervisor);
    txtDescriptionSupervisor = v.findViewById(R.id.txtDescriptionSupervisor);
    RelativeLayout layoutSupervisor = v.findViewById(R.id.rlSupervisor);
    layoutSupervisor.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            openSupervisorUser();
        }
    });
    RelativeLayout layoutUser = v.findViewById(R.id.rlUser);
    layoutUser.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            openViewUser();
        }
    });
    txtOnline = v.findViewById(R.id.txtOnline);
    imgOnline = v.findViewById(R.id.imgOnline);
    statusMQTT(cache.getOnlineStatus());
    loadSupervisor();
    loadClientInfo();
    return v;
}
Also used : AppData(org.flyve.mdm.agent.data.localstorage.AppData) RelativeLayout(android.widget.RelativeLayout) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View)

Example 2 with AppData

use of org.flyve.mdm.agent.data.localstorage.AppData in project android-mdm-agent by flyve-mdm.

the class MainActivity method onCreate.

/**
 * Called when the activity is starting
 * @param savedInstanceState if the activity is being re-initialized, it contains the data it most recently supplied
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // start MQTT
    globalStartMQTT();
    cache = new AppData(this);
    // Setup the DrawerLayout and NavigationView
    txtToolbarTitle = findViewById(R.id.txtToolbarTitle);
    mDrawerLayout = findViewById(R.id.drawerLayout);
    lstDrawer = findViewById(R.id.lstNV);
    lstDrawer.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mDrawerLayout.closeDrawers();
            selectedItem = arrDrawer.get(position);
            loadFragment(selectedItem, "");
        }
    });
    mFragmentManager = getSupportFragmentManager();
    // Setup Drawer Toggle of the Toolbar
    android.support.v7.widget.Toolbar toolbar = findViewById(R.id.toolbar);
    ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.app_name, R.string.app_name);
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    mDrawerToggle.syncState();
    // check if come from notification like DeployApp
    int menuItemSelected = 0;
    String extra = "";
    String type = getIntent().getStringExtra("From");
    if (type != null) {
        switch(type) {
            case "DeployApp":
            case "RemoveApp":
                menuItemSelected = 1;
                extra = "DeployApp";
                break;
            case "PasswordPolicy":
                AndroidPolicies androidPolicies = new AndroidPolicies(MainActivity.this, FlyveAdminReceiver.class);
                androidPolicies.enablePassword(true, "", MainActivity.class);
        }
    }
    loadListDrawer(menuItemSelected, extra);
    checkNotifications();
    PoliciesAsyncTask.sendStatusbyHttp(MainActivity.this, true);
}
Also used : ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AppData(org.flyve.mdm.agent.data.localstorage.AppData) AdapterView(android.widget.AdapterView) AndroidPolicies(org.flyve.policies.manager.AndroidPolicies)

Example 3 with AppData

use of org.flyve.mdm.agent.data.localstorage.AppData in project android-mdm-agent by flyve-mdm.

the class Helpers method sendToNotificationBar.

public static void sendToNotificationBar(Context context, int id, String title, String message, boolean isPersistence, Class<?> cls, String from) {
    AppData cache = new AppData(context);
    if (cache.getDisableNotification()) {
        return;
    }
    Intent resultIntent = new Intent(context, cls);
    resultIntent.putExtra("From", from);
    resultIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent piResult = PendingIntent.getActivity(context, 0, resultIntent, PendingIntent.FLAG_ONE_SHOT);
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.icon)).setContentTitle(title).setContentText(message).setSound(defaultSoundUri).setContentIntent(piResult).setPriority(Notification.PRIORITY_HIGH);
    if (isPersistence) {
        builder.setOngoing(true);
    } else {
        builder.setAutoCancel(true);
    }
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
        // Notification Channel
        String notificationChannelId = "1122";
        String channelName = "Flyve MDM Notifications";
        int importance = NotificationManager.IMPORTANCE_LOW;
        NotificationChannel notificationChannel = new NotificationChannel(notificationChannelId, channelName, importance);
        notificationChannel.enableLights(true);
        notificationChannel.setLightColor(Color.GREEN);
        NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        try {
            notificationManager.createNotificationChannel(notificationChannel);
            builder.setChannelId(notificationChannelId);
        } catch (Exception ex) {
            FlyveLog.e(Helpers.class.getClass().getName() + ", sendToNotificationBar", ex.getMessage());
        }
    }
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder.setSmallIcon(R.drawable.ic_notification_white);
    } else {
        builder.setSmallIcon(R.drawable.icon);
    }
    builder.setStyle(new NotificationCompat.BigTextStyle().bigText(message));
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    try {
        notificationManager.notify(id, builder.build());
    } catch (Exception ex) {
        FlyveLog.e(Helpers.class.getClass().getName() + ", deleteFolder", ex.getMessage());
    }
}
Also used : NotificationManager(android.app.NotificationManager) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) Uri(android.net.Uri) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) NotificationChannel(android.app.NotificationChannel) AppData(org.flyve.mdm.agent.data.localstorage.AppData) NotificationCompat(android.support.v4.app.NotificationCompat) PendingIntent(android.app.PendingIntent)

Example 4 with AppData

use of org.flyve.mdm.agent.data.localstorage.AppData in project android-mdm-agent by flyve-mdm.

the class MqttModel method setStatus.

private void setStatus(Context context, MqttCallback callback, Boolean isConnected) {
    // send broadcast
    this.connected = isConnected;
    // reconnect
    if (!isConnected) {
        reconnect(context, callback);
    } else {
        // send via http the status connected
        PoliciesAsyncTask.sendStatusbyHttp(context, true);
    }
    AppData cache = new AppData(context);
    cache.setOnlineStatus(isConnected);
    Helpers.sendBroadcast(isConnected, Helpers.BROADCAST_STATUS, context);
}
Also used : AppData(org.flyve.mdm.agent.data.localstorage.AppData)

Example 5 with AppData

use of org.flyve.mdm.agent.data.localstorage.AppData in project android-mdm-agent by flyve-mdm.

the class FragmentConfiguration method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    v = inflater.inflate(R.layout.fragment_configuration, container, false);
    cache = new AppData(FragmentConfiguration.this.getContext());
    Switch swNotifications = this.v.findViewById(R.id.swNotifications);
    swNotifications.setChecked(cache.getDisableNotification());
    swNotifications.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            cache.setDisableNotification(b);
        }
    });
    Switch swConnectionNotification = this.v.findViewById(R.id.swConnectionNotification);
    swConnectionNotification.setChecked(cache.getEnableNotificationConnection());
    swConnectionNotification.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            cache.setEnableNotificationConnection(b);
        }
    });
    Switch swDarkTheme = this.v.findViewById(R.id.swDarkTheme);
    swDarkTheme.setChecked(cache.getDarkTheme());
    swDarkTheme.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            cache.setDarkTheme(b);
        }
    });
    // use for lock option
    Switch switchDrawOverlay = this.v.findViewById(R.id.swtDrawOverlay);
    if (Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
        switchDrawOverlay.setChecked(Settings.canDrawOverlays(getActivity()));
        switchDrawOverlay.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getActivity().getPackageName()));
                startActivityForResult(intent, REQUEST_DRAWOVERLAY_CODE);
            }
        });
    } else {
        switchDrawOverlay.setVisibility(View.INVISIBLE);
    }
    Button btnClear = v.findViewById(R.id.btnClear);
    btnClear.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            AlertDialog.Builder builder = new AlertDialog.Builder(FragmentConfiguration.this.getContext());
            builder.setTitle(R.string.danger);
            builder.setMessage(R.string.erase_all_data_question);
            builder.setPositiveButton(R.string.YES, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int which) {
                    LocalStorage localStorage = new LocalStorage(FragmentConfiguration.this.getContext());
                    localStorage.clearSettings();
                    new MqttData(FragmentConfiguration.this.getContext()).deleteAll();
                    dialog.dismiss();
                }
            });
            builder.setNegativeButton(R.string.NO, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // Do nothing
                    dialog.dismiss();
                }
            });
            AlertDialog alert = builder.create();
            alert.show();
        }
    });
    return v;
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) MqttData(org.flyve.mdm.agent.data.database.MqttData) DialogInterface(android.content.DialogInterface) Intent(android.content.Intent) View(android.view.View) LocalStorage(org.flyve.mdm.agent.data.localstorage.LocalStorage) Switch(android.widget.Switch) AppData(org.flyve.mdm.agent.data.localstorage.AppData) CompoundButton(android.widget.CompoundButton) Button(android.widget.Button) CompoundButton(android.widget.CompoundButton)

Aggregations

AppData (org.flyve.mdm.agent.data.localstorage.AppData)5 View (android.view.View)3 Intent (android.content.Intent)2 TextView (android.widget.TextView)2 NotificationChannel (android.app.NotificationChannel)1 NotificationManager (android.app.NotificationManager)1 PendingIntent (android.app.PendingIntent)1 DialogInterface (android.content.DialogInterface)1 Uri (android.net.Uri)1 NotificationCompat (android.support.v4.app.NotificationCompat)1 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)1 AlertDialog (android.support.v7.app.AlertDialog)1 AdapterView (android.widget.AdapterView)1 Button (android.widget.Button)1 CompoundButton (android.widget.CompoundButton)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1 RelativeLayout (android.widget.RelativeLayout)1 Switch (android.widget.Switch)1 IOException (java.io.IOException)1