Skip to content

Commit afe01aa

Browse files
committed
Terminal theme preview
1 parent d81afe4 commit afe01aa

File tree

5 files changed

+56
-44
lines changed

5 files changed

+56
-44
lines changed

app/src/main/java/com/duy/ccppcompiler/console/ShellTermSession.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ public void run() {
8787
}
8888
};
8989
mWatcherThread.setName("Process watcher");
90-
9190
}
9291

9392
public void updatePrefs(TermSettings settings) {

app/src/main/java/com/duy/editor/theme/EditorThemeFragment.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public void onBindViewHolder(@NonNull final ViewHolder holder, int position) {
121121
@Override
122122
public void onClick(View v) {
123123
if (onThemeSelectListener != null) {
124-
onThemeSelectListener.onThemeSelected(editorTheme);
124+
onThemeSelectListener.onEditorThemeSelected(editorTheme);
125125
}
126126
}
127127
});
@@ -182,7 +182,7 @@ public void setOnThemeSelectListener(OnThemeSelectListener onThemeSelectListener
182182
}
183183

184184
public interface OnThemeSelectListener {
185-
void onThemeSelected(EditorTheme theme);
185+
void onEditorThemeSelected(EditorTheme theme);
186186
}
187187

188188
static class ViewHolder extends RecyclerView.ViewHolder {

app/src/main/java/com/duy/editor/theme/TerminalThemeFragment.java

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.content.Context;
44
import android.os.Bundle;
5+
import android.preference.PreferenceManager;
56
import android.support.annotation.NonNull;
67
import android.support.annotation.Nullable;
78
import android.support.v4.app.Fragment;
@@ -11,16 +12,17 @@
1112
import android.view.LayoutInflater;
1213
import android.view.View;
1314
import android.view.ViewGroup;
14-
import android.widget.TextView;
1515

1616
import com.duy.ccppcompiler.R;
17-
import com.duy.ide.editor.theme.model.EditorTheme;
1817
import com.jecelyin.editor.v2.Preferences;
1918
import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView;
2019

20+
import java.io.StringBufferInputStream;
21+
2122
import jackpal.androidterm.TermSettings;
2223
import jackpal.androidterm.emulatorview.ColorScheme;
2324
import jackpal.androidterm.emulatorview.EmulatorView;
25+
import jackpal.androidterm.emulatorview.TermSession;
2426

2527
public class TerminalThemeFragment extends Fragment {
2628
private RecyclerView mRecyclerView;
@@ -49,12 +51,15 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
4951

5052
public static class TerminalThemeAdapter extends RecyclerView.Adapter<TerminalThemeAdapter.ViewHolder> implements FastScrollRecyclerView.SectionedAdapter {
5153
private final String[] mThemes;
52-
private Context mContext;
5354
private OnThemeSelectListener onThemeSelectListener;
55+
private TermSettings mTermSettings;
56+
private Context mContext;
5457

5558
public TerminalThemeAdapter(Context context) {
5659
mContext = context;
5760
mThemes = context.getResources().getStringArray(R.array.entries_emulator_color_preference);
61+
mTermSettings = new TermSettings(context.getResources(),
62+
PreferenceManager.getDefaultSharedPreferences(context));
5863
}
5964

6065
@NonNull
@@ -65,15 +70,27 @@ public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
6570
}
6671

6772
@Override
68-
public void onBindViewHolder(@NonNull final ViewHolder holder, int position) {
69-
final String title = mThemes[position];
70-
holder.mTxtName.setText(title);
73+
public void onBindViewHolder(@NonNull final ViewHolder holder, final int position) {
7174
EmulatorView termView = holder.mTermView;
75+
TermSession session = new TermSession();
76+
session.setTermIn(new StringBufferInputStream(mThemes[position]));
77+
termView.attachSession(session);
78+
termView.setDensity(mContext.getResources().getDisplayMetrics());
79+
termView.setTextSize(16);
7280
termView.setColorScheme(new ColorScheme(TermSettings.COLOR_SCHEMES[position]));
81+
82+
holder.mBtnSelect.setOnClickListener(new View.OnClickListener() {
83+
@Override
84+
public void onClick(View v) {
85+
if (onThemeSelectListener != null){
86+
onThemeSelectListener.onTerminalThemeSelected(mThemes[position],position);
87+
}
88+
}
89+
});
7390
}
7491

75-
private String makeTitle(int position, EditorTheme editorTheme) {
76-
return (position + 1) + ". " + editorTheme.getName();
92+
private String makeTitle(int position, String name) {
93+
return (position + 1) + ". " + name;
7794
}
7895

7996
@Override
@@ -93,18 +110,16 @@ public void setOnThemeSelectListener(OnThemeSelectListener onThemeSelectListener
93110
}
94111

95112
public interface OnThemeSelectListener {
96-
void onThemeSelected(EditorTheme theme);
113+
void onTerminalThemeSelected(String mTheme, int index);
97114
}
98115

99116
static class ViewHolder extends RecyclerView.ViewHolder {
100117
View mBtnSelect;
101118
EmulatorView mTermView;
102-
TextView mTxtName;
103119

104-
public ViewHolder(View itemView) {
120+
ViewHolder(View itemView) {
105121
super(itemView);
106122
mTermView = itemView.findViewById(R.id.term_view);
107-
mTxtName = itemView.findViewById(R.id.txt_name);
108123
mBtnSelect = itemView.findViewById(R.id.btn_select);
109124
}
110125
}

app/src/main/java/com/duy/editor/theme/ThemeActivity.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ protected void onDestroy() {
104104
}
105105

106106
@Override
107-
public void onThemeSelected(EditorTheme theme) {
107+
public void onEditorThemeSelected(EditorTheme theme) {
108108
if (Premium.isPremiumUser(this)) {
109109
mPreferences.setEditorTheme(theme.getFileName());
110110
String text = getString(R.string.selected_theme, theme.getName());
@@ -115,4 +115,15 @@ public void onThemeSelected(EditorTheme theme) {
115115
}
116116
}
117117

118+
@Override
119+
public void onTerminalThemeSelected(String name, int index) {
120+
if (Premium.isPremiumUser(this)) {
121+
mPreferences.setTerminalTheme(index);
122+
String text = getString(R.string.selected_theme, name);
123+
Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
124+
} else {
125+
PremiumDialog premiumDialog = new PremiumDialog(this, mInAppPurchaseHelper);
126+
premiumDialog.show();
127+
}
128+
}
118129
}
Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,25 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
34
android:layout_width="match_parent"
45
android:layout_height="wrap_content"
5-
android:layout_marginTop="4dp"
6-
android:orientation="vertical">
7-
8-
<LinearLayout
9-
android:layout_width="match_parent"
10-
android:layout_height="wrap_content"
11-
android:paddingLeft="16dp"
12-
android:paddingRight="16dp">
13-
14-
<android.support.v7.widget.AppCompatTextView
15-
android:id="@+id/txt_name"
16-
android:layout_width="0dp"
17-
android:layout_height="wrap_content"
18-
android:layout_weight="1"
19-
android:padding="4dp"
20-
android:textAppearance="@style/TextAppearance.AppCompat.Title" />
21-
22-
<android.support.v7.widget.AppCompatButton
23-
android:id="@+id/btn_select"
24-
android:layout_width="wrap_content"
25-
android:layout_height="wrap_content"
26-
android:src="@drawable/baseline_check_24"
27-
android:text="Select" />
28-
29-
</LinearLayout>
6+
android:orientation="horizontal">
307

318
<jackpal.androidterm.emulatorview.EmulatorView
329
android:id="@+id/term_view"
3310
android:layout_width="match_parent"
34-
android:layout_height="wrap_content">
11+
android:layout_height="50dp"
12+
tools:background="#000">
3513

3614
</jackpal.androidterm.emulatorview.EmulatorView>
37-
</LinearLayout>
15+
16+
<android.support.v7.widget.AppCompatButton
17+
android:id="@+id/btn_select"
18+
android:layout_width="wrap_content"
19+
android:layout_height="wrap_content"
20+
android:layout_gravity="end"
21+
android:src="@drawable/baseline_check_24"
22+
android:text="Select" />
23+
24+
</FrameLayout>
3825

0 commit comments

Comments
 (0)