Skip to content

Commit

Permalink
Enable & Disable PAL / NTSC selector #3 #4
Browse files Browse the repository at this point in the history
  • Loading branch information
ma1co committed May 6, 2016
1 parent 0191b18 commit 937ecb1
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ public class BackupKeys {
for (int i = 0; i < LANGUAGE_ACTIVE_COUNT; i++)
LANGUAGE_ACTIVE_LIST[i] = LANGUAGE_ACTIVE_FIRST + i;
}

public static final int PAL_NTSC_SELECTOR_ENABLED = 0x01070148;
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.github.ma1co.openmemories.tweak;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class LanguageActivity extends BaseActivity {
public class LanguageActivity extends BaseActivity implements SwitchView.CheckedListener {
public static final int[] LANG_ALL = new int[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
public static final int[] LANG_APAC = new int[] { 1, 2, 1, 2, 1, 2, 1, 1, 1, 1, 1, 2, 2, 1, 1, 2, 2, 2, 2, 2, 1, 2, 2, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 };
public static final int[] LANG_CN = new int[] { 1, 2, 1, 2, 1, 2, 1, 1, 1, 1, 1, 2, 2, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 };
Expand Down Expand Up @@ -32,27 +30,25 @@ else if ("UC2".equals(r))
public static final int LANGUAGE_ENABLED = 1;
public static final int LANGUAGE_DISABLED = 2;

private TextView langTextView;
private SwitchView langSwitch;
private SwitchView palNtscSwitch;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_language);
langTextView = (TextView) findViewById(R.id.langTextView);

langSwitch = (SwitchView) findViewById(R.id.lang_switch);
langSwitch.setListener(this);
palNtscSwitch = (SwitchView) findViewById(R.id.pal_ntsc_switch);
palNtscSwitch.setListener(this);
}

@Override
protected void onResume() {
super.onResume();
showActiveLanguages();
}

protected void readCheck() throws BackupCheckException {
checkBackupByteValues(BackupKeys.LANGUAGE_ACTIVE_LIST, LANGUAGE_ENABLED, LANGUAGE_DISABLED);
}

protected void writeCheck() throws BackupCheckException {
checkBackupWritable(BackupKeys.LANGUAGE_ACTIVE_LIST);
showPalNtscEnabled();
}

protected boolean[] readActiveLanguages() throws NativeException {
Expand All @@ -68,17 +64,18 @@ protected void writeActiveLanguages(int[] langs) throws NativeException {
}

protected void showActiveLanguages() {
langTextView.setText("???");
try {
Logger.info("showActiveLanguages", "attempting to read active languages");
readCheck();
checkBackupByteValues(BackupKeys.LANGUAGE_ACTIVE_LIST, LANGUAGE_ENABLED, LANGUAGE_DISABLED);
boolean[] langs = readActiveLanguages();
int count = 0;
for (boolean active : langs)
count += active ? 1 : 0;
langTextView.setText(String.format("%d / %d", count, langs.length));
langSwitch.setChecked(count == langs.length);
langSwitch.setSummary(String.format("%d / %d activated", count, langs.length));
Logger.info("showActiveLanguages", "done: " + count);
} catch (Exception e) {
langSwitch.setEnabled(false);
Logger.error("showActiveLanguages", e);
showError(e);
}
Expand All @@ -87,15 +84,14 @@ protected void showActiveLanguages() {
protected void setActiveLanguages(int[] langs) {
try {
Logger.info("setActiveLanguages", "attempting to write active languages");
readCheck();
writeCheck();
checkBackupWritable(BackupKeys.LANGUAGE_ACTIVE_LIST);
writeActiveLanguages(langs);
showActiveLanguages();
Logger.info("setActiveLanguages", "done");
} catch (Exception e) {
Logger.error("setActiveLanguages", e);
showError(e);
}
showActiveLanguages();
}

protected void resetActiveLanguages() {
Expand All @@ -114,11 +110,51 @@ protected void resetActiveLanguages() {
}
}

public void onActivateAllButtonClicked(View view) {
setActiveLanguages(LANG_ALL);
protected boolean readPalNtscEnabled() throws NativeException {
return Backup.getValue(BackupKeys.PAL_NTSC_SELECTOR_ENABLED)[0] == 1;
}

protected void writePalNtscEnabled(boolean enabled) throws NativeException {
Backup.setValue(BackupKeys.PAL_NTSC_SELECTOR_ENABLED, new byte[] {(byte) (enabled ? 1 : 0)});
}

protected void showPalNtscEnabled() {
try {
Logger.info("showPalNtscEnabled", "attempting to read pal / ntsc");
checkBackupByteValues(new int[] {BackupKeys.PAL_NTSC_SELECTOR_ENABLED}, 0, 1);
boolean enabled = readPalNtscEnabled();
palNtscSwitch.setChecked(enabled);
palNtscSwitch.setSummary(String.format(enabled ? "Enabled" : "Disabled"));
Logger.info("showPalNtscEnabled", "done: " + enabled);
} catch (Exception e) {
palNtscSwitch.setEnabled(false);
Logger.error("showPalNtscEnabled", e);
showError(e);
}
}

protected void setPalNtscEnabled(boolean enabled) {
try {
Logger.info("setPalNtscEnabled", "attempting to write pal / ntsc: " + enabled);
checkBackupWritable(new int[] {BackupKeys.PAL_NTSC_SELECTOR_ENABLED});
writePalNtscEnabled(enabled);
Logger.info("setPalNtscEnabled", "done");
} catch (Exception e) {
Logger.error("setPalNtscEnabled", e);
showError(e);
}
showPalNtscEnabled();
}

public void onResetButtonClicked(View view) {
resetActiveLanguages();
@Override
public void onCheckedChanged(SwitchView view, boolean checked) {
if (langSwitch.equals(view)) {
if (checked)
setActiveLanguages(LANG_ALL);
else
resetActiveLanguages();
} else if(palNtscSwitch.equals(view)) {
setPalNtscEnabled(checked);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void uncaughtException(Thread thread, Throwable exp) {
addTab("video4k", "4k Video", android.R.drawable.ic_menu_camera, VideoActivity4k.class);
}
} catch(NativeException e) { /* no op */ }
addTab("lang", "Languages", android.R.drawable.ic_menu_mapmode, LanguageActivity.class);
addTab("region", "Region", android.R.drawable.ic_menu_mapmode, LanguageActivity.class);
addTab("protection", "Protection", android.R.drawable.ic_lock_lock, ProtectionActivity.class);
addTab("developer", "Developer", android.R.drawable.ic_menu_manage, DeveloperActivity.class);
}
Expand Down
30 changes: 8 additions & 22 deletions app/src/main/res/layout/activity_language.xml
Original file line number Diff line number Diff line change
@@ -1,34 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tweak="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Currently active languages:"/>

<TextView
<com.github.ma1co.openmemories.tweak.SwitchView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="40sp"
android:padding="5sp"
android:id="@+id/langTextView"/>
android:id="@+id/lang_switch"
tweak:title="Enable all languages"/>

<Button
android:layout_width="200sp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Activate all"
android:onClick="onActivateAllButtonClicked"/>

<Button
android:layout_width="200sp"
<com.github.ma1co.openmemories.tweak.SwitchView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Reset to default"
android:onClick="onResetButtonClicked"/>
android:id="@+id/pal_ntsc_switch"
tweak:title="Enable PAL / NTSC selector &amp; warning"/>

</LinearLayout>

0 comments on commit 937ecb1

Please sign in to comment.