Skip to content
This repository has been archived by the owner on Feb 25, 2022. It is now read-only.

Commit

Permalink
Add watermark
Browse files Browse the repository at this point in the history
  • Loading branch information
seven332 committed Nov 13, 2015
1 parent 5af0ffa commit db1f422
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/src/main/java/com/hippo/nimingban/client/ac/ACEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,11 @@ public static Call prepareReply(OkHttpClient okHttpClient, ACReplyStruct struct)
builder.addPart(
Headers.of("Content-Disposition", "form-data; name=\"resto\""),
RequestBody.create(null, StringUtils.avoidNull(struct.resto)));
if (struct.water) {
builder.addPart(
Headers.of("Content-Disposition", "form-data; name=\"water\""),
RequestBody.create(null, "true"));
}
InputStreamPipe isPipe = struct.image;

if (isPipe != null) {
Expand Down Expand Up @@ -499,6 +504,11 @@ public static Call prepareCreatePost(OkHttpClient okHttpClient, ACPostStruct str
builder.addPart(
Headers.of("Content-Disposition", "form-data; name=\"fid\""),
RequestBody.create(null, StringUtils.avoidNull(struct.fid)));
if (struct.water) {
builder.addPart(
Headers.of("Content-Disposition", "form-data; name=\"water\""),
RequestBody.create(null, "true"));
}
InputStreamPipe isPipe = struct.image;

if (isPipe != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ public class ACPostStruct {
public String fid;
public InputStreamPipe image;
public String imageType;
public boolean water;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ public class ACReplyStruct {
public String resto;
public InputStreamPipe image;
public String imageType;
public boolean water;
}
13 changes: 13 additions & 0 deletions app/src/main/java/com/hippo/nimingban/ui/TypeSendActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@
import android.view.ViewGroup;
import android.webkit.MimeTypeMap;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

Expand Down Expand Up @@ -139,6 +141,7 @@ public final class TypeSendActivity extends TranslucentActivity implements View.
private EditText mName;
private EditText mEmail;
private EditText mTitle;
private CheckBox mWatermark;
private TextView mMoreWritableItemsText;
private View mSelectForum;
private TextView mForumText;
Expand Down Expand Up @@ -255,6 +258,7 @@ protected void onCreate(Bundle savedInstanceState) {
mName = (EditText) findViewById(R.id.name);
mEmail = (EditText) findViewById(R.id.email);
mTitle = (EditText) findViewById(R.id.title);
mWatermark = (CheckBox) findViewById(R.id.watermark);
mMoreWritableItemsText = (TextView) findViewById(R.id.more_writable_items_text);
mSelectForum = findViewById(R.id.select_forum);
mForumText = (TextView) mSelectForum.findViewById(R.id.forum_text);
Expand All @@ -281,6 +285,13 @@ protected void onCreate(Bundle savedInstanceState) {
drawable.addState(new int[]{}, VectorDrawable.create(this, R.drawable.ic_chevron_down));
mIndicator.setDrawable(drawable);

mWatermark.setChecked(Settings.getWatermark());
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mWatermark.getLayoutParams();
lp.leftMargin = mTitle.getPaddingLeft() - LayoutUtils.dp2pix(this, 5);
mWatermark.setLayoutParams(lp);
mWatermark.setPadding(mWatermark.getPaddingLeft() + LayoutUtils.dp2pix(this, 4),
mWatermark.getPaddingTop(), mWatermark.getPaddingRight(), mWatermark.getPaddingBottom());

mWritableItem.setVisibility(View.GONE);

if (mShare) {
Expand Down Expand Up @@ -505,6 +516,7 @@ private void doReply() {
struct.resto = mId;
struct.image = mSeletedImageUri != null ? new UriInputStreamPipe(getApplicationContext(), mSeletedImageUri) : null;
struct.imageType = mSeletedImageType;
struct.water = mWatermark.isChecked();

NMBRequest request = new NMBRequest();
request.setSite(mSite);
Expand All @@ -525,6 +537,7 @@ private void doCreatePost() {
struct.fid = mId;
struct.image = mSeletedImageUri != null ? new UriInputStreamPipe(getApplicationContext(), mSeletedImageUri) : null;
struct.imageType = mSeletedImageType;
struct.water = mWatermark.isChecked();

NMBRequest request = new NMBRequest();
request.setSite(mSite);
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/com/hippo/nimingban/util/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ public static void putIntToStr(String key, int value) {
public static final String KEY_COLOR_STATUS_BAR = "color_status_bar";
public static final boolean DEFAULT_COLOR_STATUS_BAR = true;

public static final String KEY_WATERMARK = "watermark";
public static final boolean DEFAULT_WATERMARKD = true;

public static final String KEY_FEED_ID = "feed_id";
public static final String DEFAULT_FEED_ID = null;

Expand Down Expand Up @@ -222,6 +225,10 @@ public static boolean getColorStatusBar() {
return getBoolean(KEY_COLOR_STATUS_BAR, DEFAULT_COLOR_STATUS_BAR);
}

public static boolean getWatermark() {
return getBoolean(KEY_WATERMARK, DEFAULT_WATERMARKD);
}

public static String getFeedId() {
if (sExtendFeedId != null) {
return sExtendFeedId;
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/res/layout/activity_type_send_content_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,19 @@
android:layout_height="1dp"
android:background="?attr/colorDivider"/>

<CheckBox
android:id="@+id/watermark"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="48dp"
android:text="@string/type_send_watermark"
android:textSize="@dimen/text_little_small"/>

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/colorDivider"/>

</LinearLayout>

<EditText
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@
<string name="type_send_name">名称</string>
<string name="type_send_email">E-mail</string>
<string name="type_send_title">标题</string>
<string name="type_send_watermark">水印</string>

<string name="doodle">涂鸦</string>
<string name="save_doodle">保存涂鸦?</string>
Expand Down Expand Up @@ -225,6 +226,9 @@
<string name="main_save_cookies_summary">保存饼干至外置存储器</string>
<string name="main_restore_cookies">恢复饼干</string>
<string name="main_restore_cookies_summary">从外置存储器的饼干文件中恢复饼干</string>
<string name="main_watermark">水印</string>
<string name="main_watermark_summary_on">在你上传的图片中显示水印</string>
<string name="main_watermark_summary_off">不在你上传的图片中显示水印</string>
<string name="main_feed_id">订阅 ID</string>
<string name="main_feed_id_summary">你的订阅 ID 是 %s</string>
<string name="main_save_image_auto">自动存图</string>
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
<string name="type_send_name">Name</string>
<string name="type_send_email">E-mail</string>
<string name="type_send_title">Title</string>
<string name="type_send_watermark">Watermark</string>

<string name="doodle">Doodle</string>
<string name="save_doodle">Save doodle?</string>
Expand Down Expand Up @@ -232,6 +233,9 @@
<string name="main_save_cookies_summary">Save cookies to external storage</string>
<string name="main_restore_cookies">Restore cookies</string>
<string name="main_restore_cookies_summary">Restore cookies from a file in external storage</string>
<string name="main_watermark">Watermark</string>
<string name="main_watermark_summary_on">Show watermark in the image you upload</string>
<string name="main_watermark_summary_off">Don\'t show watermark in the image you upload</string>
<string name="main_feed_id">Feed id</string>
<string name="main_feed_id_summary">You feed id is %s</string>
<string name="main_save_image_auto">Save image when loaded</string>
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/xml/config_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@
android:title="@string/main_restore_cookies"
android:summary="@string/main_restore_cookies_summary"/>

<com.hippo.preference.FixedSwitchPreference
style="?android:attr/preferenceStyle"
android:key="watermark"
android:title="@string/main_watermark"
app:summaryOn="@string/main_watermark_summary_on"
app:summaryOff="@string/main_watermark_summary_off"
android:defaultValue="true"
android:widgetLayout="@layout/preference_widget_fixed_switch"/>

<Preference
android:key="feed_id"
android:title="@string/main_feed_id"/>
Expand Down

0 comments on commit db1f422

Please sign in to comment.