Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.NumberPicker;

import com.gmail.afonsotrepa.pocketgopher.gopherclient.Page;

Expand All @@ -28,7 +29,9 @@ public class MainActivity extends AppCompatActivity
{
private Menu menu;
public static int font = R.style.monospace;
public static int fontSize = 14; // 14sp is the default textview text size

private static final String FONT_SIZE_SETTING = "font_size";
private static final String MONOSPACE_FONT_SETTING = "monospace_font";
private static final String FIRST_RUN = "first_run";

Expand All @@ -49,6 +52,8 @@ protected void onCreate(Bundle savedInstanceState)
font = R.style.serif;
}

fontSize = sharedPreferences.getInt(FONT_SIZE_SETTING, fontSize);

if (sharedPreferences.getBoolean(FIRST_RUN, true))
{
editor.putBoolean(FIRST_RUN, false);
Expand Down Expand Up @@ -179,13 +184,15 @@ public boolean onCreateOptionsMenu(Menu menu)
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
// get the preferences editor
final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
final SharedPreferences.Editor editor = sharedPreferences.edit();
// get a dialog builder
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);

switch (item.getItemId())
{
case R.id.monospace_font:
SharedPreferences sharedPreferences = PreferenceManager
.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = sharedPreferences.edit();

if (font == R.style.serif)
{
font = R.style.monospace;
Expand All @@ -205,9 +212,44 @@ public boolean onOptionsItemSelected(MenuItem item)

return true;

case R.id.font_size:
//create the font size number picker
final NumberPicker numberPicker = new NumberPicker(this);
numberPicker.setMinValue(1);
numberPicker.setMaxValue(64);
numberPicker.setValue(sharedPreferences.getInt(FONT_SIZE_SETTING, 12));

//setup the dialog with the number picker
alertDialog.setMessage("Font Size");
alertDialog.setView(numberPicker);

final MainActivity activity = this;

//setup the ok button callback to save the number picker value into shared preferences
alertDialog.setPositiveButton("OK",
new DialogInterface.OnClickListener()
{
@Override
public void onClick(final DialogInterface dialog, int which)
{
// get the new font size from number picker
int newFontSize = numberPicker.getValue();
// store the new font size setting into shared preferences
editor.putInt(FONT_SIZE_SETTING, newFontSize);
editor.apply();
// update the current font size
activity.fontSize = newFontSize;
}
}
);

// show the dialog
alertDialog.show();

return true;

case R.id.link:
//create the dialog to be shown when the button gets clicked
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
alertDialog.setMessage("URL:");

//setup the EditText where the user will input url to the page
Expand All @@ -220,7 +262,6 @@ public boolean onOptionsItemSelected(MenuItem item)
input.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
alertDialog.setView(input);


alertDialog.setPositiveButton("Go",
new DialogInterface.OnClickListener()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ protected void onCreate(Bundle savedInstaceState)

final TextView textView = findViewById(R.id.textView);
textView.setTextAppearance(this, MainActivity.font);
textView.setTextSize(MainActivity.fontSize);
textView.setMovementMethod(LinkMovementMethod.getInstance());

final Context context = this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ protected void onCreate(Bundle savedInstanceState)
final TextView textView = (TextView) findViewById(R.id.textView);
//set the font
textView.setTextAppearance(this, MainActivity.font);
textView.setTextSize(MainActivity.fontSize);

//start a new thread to do network stuff
new Thread(new Runnable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void run()
text.setSpan(cs1, 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
text.setSpan(cs2, 2, text.length() - 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
//set the image tag behind (left of) the text
text.setSpan(new ImageSpan(context, IMAGE_TAG), 0, 1, 0);
text.setSpan(Page.formatIcon(context, textView, IMAGE_TAG), 0, 1, 0);
//add it to the end of textView
textView.append(text);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void run()
text.setSpan(cs1, 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
text.setSpan(cs2, 2, text.length() - 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
//set the image tag behind (left of) the text
text.setSpan(new ImageSpan(context, IMAGE_TAG), 0, 1, 0);
text.setSpan(Page.formatIcon(context, textView, IMAGE_TAG), 0, 1, 0);
//add it to the end of textView
textView.append(text);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void run()
text.setSpan(cs1, 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
text.setSpan(cs2, 2, text.length() - 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
//set the image tag behind (left of) the text
text.setSpan(new ImageSpan(context, IMAGE_TAG), 0, 1, 0);
text.setSpan(Page.formatIcon(context, textView, IMAGE_TAG), 0, 1, 0);
//add it to the end of textView
textView.append(text);
}
Expand Down Expand Up @@ -155,4 +155,4 @@ public void run()
Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void run()
text.setSpan(cs1, 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
text.setSpan(cs2, 2, text.length() - 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
//set the image tag behind (left of) the text
text.setSpan(new ImageSpan(context, IMAGE_TAG), 0, 1, 0);
text.setSpan(Page.formatIcon(context, textView, IMAGE_TAG), 0, 1, 0);
//add it to the end of textView
textView.append(text);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void run()
text.setSpan(cs1, 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
text.setSpan(cs2, 2, text.length() - 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
//set the image tag behind (left of) the text
text.setSpan(new ImageSpan(context, IMAGE_TAG), 0, 1, 0);
text.setSpan(Page.formatIcon(context, textView, IMAGE_TAG) , 0, 1, 0);
//add it to the end of textView
textView.append(text);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.text.style.ImageSpan;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
Expand Down Expand Up @@ -55,6 +57,12 @@ public Page(String server, Integer port, Character type, String selector)
this(server, port, type, selector, null);
}

public static ImageSpan formatIcon(Context context, TextView textView, int resourceID) {
Drawable icon = context.getDrawable(resourceID);
int iconSize = (int)((double)textView.getLineHeight()*2.5);
icon.setBounds(0, 0, iconSize, iconSize);
return new ImageSpan(icon, 0);
}

public abstract void open(final Context context);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void run()
text.setSpan(cs1, 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
text.setSpan(cs2, 2, text.length() - 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
//set the image tag behind (left of) the text
text.setSpan(new ImageSpan(context, IMAGE_TAG), 0, 1, 0);
text.setSpan(Page.formatIcon(context, textView, IMAGE_TAG), 0, 1, 0);
//add it to the end of textView
textView.append(text);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void run()
text.setSpan(cs1, 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
text.setSpan(cs2, 2, text.length() - 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
//set the image tag behind (left of) the text
text.setSpan(new ImageSpan(context, IMAGE_TAG), 0, 1, 0);
text.setSpan(Page.formatIcon(context, textView, IMAGE_TAG), 0, 1, 0);
//add it to the end of textView
textView.append(text);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void render(final TextView textView, final Context context, String line)
public void run()
{
//set the image tag behind (left of) the text
text.setSpan(new ImageSpan(context, IMAGE_TAG), 0, 1, 0);
text.setSpan(Page.formatIcon(context, textView, IMAGE_TAG), 0, 1, 0);
textView.append(text);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void run()
text.setSpan(cs1, 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
text.setSpan(cs2, 2, text.length() - 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
//set the image tag behind (left of) the text
text.setSpan(new ImageSpan(context, IMAGE_TAG), 0, 1, 0);
text.setSpan(Page.formatIcon(context, textView, IMAGE_TAG), 0, 1, 0);
//add it to the end of textView
textView.append(text);
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:autoSizeTextType="uniform"
android:autoSizeTextType="none"
android:textIsSelectable="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/res/menu/client_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
android:visible="true"
app:showAsAction="never" />

<item
android:id="@+id/font_size"
android:title="Font size"
android:visible="true"
app:showAsAction="never" />

<item
android:id="@+id/link"
android:enabled="true"
Expand All @@ -25,4 +31,4 @@
android:title="History"
android:visible="true"
app:showAsAction="ifRoom" />
</menu>
</menu>