Skip to content

Commit cb0468a

Browse files
committed
move WPUnderlineSpan.java and MediaGalleryImageSpan.java to WPUtils
1 parent d9c1111 commit cb0468a

File tree

3 files changed

+156
-0
lines changed

3 files changed

+156
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
2+
package org.wordpress.android.util.helpers;
3+
4+
import java.io.Serializable;
5+
import java.util.ArrayList;
6+
7+
/**
8+
* A model representing a Media Gallery.
9+
* A unique id is not used on the website, but only in this app.
10+
* It is used to uniquely determining the instance of the object, as it is
11+
* passed between post and media gallery editor.
12+
*/
13+
public class MediaGallery implements Serializable {
14+
private static final long serialVersionUID = 2359176987182027508L;
15+
16+
private long uniqueId;
17+
private boolean isRandom;
18+
private String type;
19+
private int numColumns;
20+
private ArrayList<String> ids;
21+
22+
public MediaGallery(boolean isRandom, String type, int numColumns, ArrayList<String> ids) {
23+
this.isRandom = isRandom;
24+
this.type = type;
25+
this.numColumns = numColumns;
26+
this.ids = ids;
27+
this.uniqueId = System.currentTimeMillis();
28+
}
29+
30+
public MediaGallery() {
31+
isRandom = false;
32+
type = "";
33+
numColumns = 3;
34+
ids = new ArrayList<String>();
35+
this.uniqueId = System.currentTimeMillis();
36+
}
37+
38+
public boolean isRandom() {
39+
return isRandom;
40+
}
41+
42+
public void setRandom(boolean isRandom) {
43+
this.isRandom = isRandom;
44+
}
45+
46+
public String getType() {
47+
return type;
48+
}
49+
50+
public void setType(String type) {
51+
this.type = type;
52+
}
53+
54+
public int getNumColumns() {
55+
return numColumns;
56+
}
57+
58+
public void setNumColumns(int numColumns) {
59+
this.numColumns = numColumns;
60+
}
61+
62+
public ArrayList<String> getIds() {
63+
return ids;
64+
}
65+
66+
public String getIdsStr() {
67+
String ids_str = "";
68+
if (ids.size() > 0) {
69+
for (String id : ids) {
70+
ids_str += id + ",";
71+
}
72+
ids_str = ids_str.substring(0, ids_str.length() - 1);
73+
}
74+
return ids_str;
75+
}
76+
77+
public void setIds(ArrayList<String> ids) {
78+
this.ids = ids;
79+
}
80+
81+
/**
82+
* An id to uniquely identify a media gallery object, so that the same object can be edited in the post editor
83+
*/
84+
public long getUniqueId() {
85+
return uniqueId;
86+
}
87+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.wordpress.android.util.helpers;
2+
3+
import android.content.Context;
4+
import android.text.style.ImageSpan;
5+
6+
public class MediaGalleryImageSpan extends ImageSpan {
7+
private MediaGallery mMediaGallery;
8+
9+
public MediaGalleryImageSpan(Context context, MediaGallery mediaGallery, int placeHolder) {
10+
super(context, placeHolder);
11+
setMediaGallery(mediaGallery);
12+
}
13+
14+
public MediaGallery getMediaGallery() {
15+
return mMediaGallery;
16+
}
17+
18+
public void setMediaGallery(MediaGallery mediaGallery) {
19+
this.mMediaGallery = mediaGallery;
20+
}
21+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (C) 2006 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.wordpress.android.util.helpers;
18+
19+
import android.os.Parcel;
20+
import android.text.ParcelableSpan;
21+
import android.text.TextPaint;
22+
import android.text.style.CharacterStyle;
23+
import android.text.style.UpdateAppearance;
24+
25+
public class WPUnderlineSpan extends CharacterStyle
26+
implements UpdateAppearance, ParcelableSpan {
27+
public WPUnderlineSpan() {
28+
}
29+
30+
public WPUnderlineSpan(Parcel src) {
31+
}
32+
33+
public int getSpanTypeId() {
34+
return 6;
35+
}
36+
37+
public int describeContents() {
38+
return 0;
39+
}
40+
41+
public void writeToParcel(Parcel dest, int flags) {
42+
}
43+
44+
@Override
45+
public void updateDrawState(TextPaint ds) {
46+
ds.setUnderlineText(true);
47+
}
48+
}

0 commit comments

Comments
 (0)