Search in sources :

Example 1 with SparseIntArrayAdapter

use of ru.playsoftware.j2meloader.util.SparseIntArrayAdapter in project J2ME-Loader by nikita36078.

the class KeyMapperActivity method onSaveInstanceState.

@Override
protected void onSaveInstanceState(@NonNull Bundle outState) {
    if (!equalMaps(androidToMIDP, defaultKeyMap)) {
        if (!equalMaps(params.keyMappings, androidToMIDP)) {
            String currMap = new GsonBuilder().registerTypeAdapter(SparseIntArray.class, new SparseIntArrayAdapter()).create().toJson(androidToMIDP);
            outState.putString(KEY_SAVE, currMap);
        } else {
            outState.putString(KEY_SAVE, "");
        }
    }
    super.onSaveInstanceState(outState);
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) SparseIntArrayAdapter(ru.playsoftware.j2meloader.util.SparseIntArrayAdapter)

Example 2 with SparseIntArrayAdapter

use of ru.playsoftware.j2meloader.util.SparseIntArrayAdapter in project J2ME-Loader by nikita36078.

the class KeyMapperActivity method onCreate.

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Intent intent = getIntent();
    String path = intent.getDataString();
    if (path == null) {
        Toast.makeText(this, "Error", Toast.LENGTH_SHORT).show();
        finish();
        return;
    }
    setContentView(R.layout.activity_keymapper);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setTitle(R.string.pref_map_keys);
    }
    params = ProfilesManager.loadConfig(new File(path));
    keyMapperLayer = findViewById(R.id.keyMapperLayer);
    popupLayout = findViewById(R.id.keyMapperPopup);
    popupMsg = findViewById(R.id.keyMapperPopupMsg);
    setupButton(R.id.virtual_key_left_soft, Canvas.KEY_SOFT_LEFT);
    setupButton(R.id.virtual_key_right_soft, Canvas.KEY_SOFT_RIGHT);
    setupButton(R.id.virtual_key_d, Canvas.KEY_SEND);
    setupButton(R.id.virtual_key_c, Canvas.KEY_END);
    setupButton(R.id.virtual_key_left, Canvas.KEY_LEFT);
    setupButton(R.id.virtual_key_right, Canvas.KEY_RIGHT);
    setupButton(R.id.virtual_key_up, Canvas.KEY_UP);
    setupButton(R.id.virtual_key_down, Canvas.KEY_DOWN);
    setupButton(R.id.virtual_key_f, Canvas.KEY_FIRE);
    setupButton(R.id.virtual_key_1, Canvas.KEY_NUM1);
    setupButton(R.id.virtual_key_2, Canvas.KEY_NUM2);
    setupButton(R.id.virtual_key_3, Canvas.KEY_NUM3);
    setupButton(R.id.virtual_key_4, Canvas.KEY_NUM4);
    setupButton(R.id.virtual_key_5, Canvas.KEY_NUM5);
    setupButton(R.id.virtual_key_6, Canvas.KEY_NUM6);
    setupButton(R.id.virtual_key_7, Canvas.KEY_NUM7);
    setupButton(R.id.virtual_key_8, Canvas.KEY_NUM8);
    setupButton(R.id.virtual_key_9, Canvas.KEY_NUM9);
    setupButton(R.id.virtual_key_0, Canvas.KEY_NUM0);
    setupButton(R.id.virtual_key_star, Canvas.KEY_STAR);
    setupButton(R.id.virtual_key_pound, Canvas.KEY_POUND);
    setupButton(R.id.virtual_key_a, KeyMapper.SE_KEY_SPECIAL_GAMING_A);
    setupButton(R.id.virtual_key_b, KeyMapper.SE_KEY_SPECIAL_GAMING_B);
    setupButton(R.id.virtual_key_menu, KeyMapper.KEY_OPTIONS_MENU);
    if (savedInstanceState == null) {
        SparseIntArray keyMap = params.keyMappings;
        androidToMIDP = keyMap == null ? defaultKeyMap.clone() : keyMap.clone();
    } else {
        String save = savedInstanceState.getString(KEY_SAVE);
        if (save == null) {
            androidToMIDP = defaultKeyMap.clone();
        } else if (save.isEmpty()) {
            SparseIntArray keyMap = params.keyMappings;
            androidToMIDP = keyMap == null ? defaultKeyMap.clone() : keyMap.clone();
        } else {
            androidToMIDP = new GsonBuilder().registerTypeAdapter(SparseIntArray.class, new SparseIntArrayAdapter()).create().fromJson(save, SparseIntArray.class);
        }
    }
}
Also used : SparseIntArray(android.util.SparseIntArray) GsonBuilder(com.google.gson.GsonBuilder) Intent(android.content.Intent) File(java.io.File) ActionBar(androidx.appcompat.app.ActionBar) SparseIntArrayAdapter(ru.playsoftware.j2meloader.util.SparseIntArrayAdapter)

Aggregations

GsonBuilder (com.google.gson.GsonBuilder)2 SparseIntArrayAdapter (ru.playsoftware.j2meloader.util.SparseIntArrayAdapter)2 Intent (android.content.Intent)1 SparseIntArray (android.util.SparseIntArray)1 ActionBar (androidx.appcompat.app.ActionBar)1 File (java.io.File)1